Jump to content


Photo

How to enable global var in SMS?


  • Please log in to reply
2 replies to this topic

#1 Laksekjønn

Laksekjønn
  • Members
  • 440 posts

Posted 27 May 2016 - 01:19 AM

Smart Mobile code insight exposes some global vars and queues utilities. In SMS there are local & cookie storage objects which expose similar functionality to global vars. I'm just interesting in using this global var through the units. How do you enable these global vars?

CleanupGlobalVars;

var backup = SaveGlobalVarsToString;

WriteGlobalVar('test', 'hello world');
WriteGlobalVar('testNum', 123);
WriteGlobalVar('testFloat', 2.5);
WriteGlobalVar('testBool', True);

LoadGlobalVarsFromString(backup);

ReadGlobalVar('test');
ReadGlobalVar('testNum');
ReadGlobalVar('testFloat');
ReadGlobalVar('testBool');

Background information:

======================

Global Var: is accessed through the ReadGlobalVar(name) and WriteGlobalVar(name, value) functions. They allow reading and writing a value by name, in an in-memory dictionary. Read & write operations are atomic.

While they’re quite self-sufficient on their own, you’ll usually want to access them through a minimal wrapper functions that’ll handle namespaces.

Here is the complete list of Global var functions:

ReadGlobalVar(name) : reads the variable of given name, returns Null if not defined
ReadGlobalVarDef(name, default) : reads the variable of given name, returns default if not defined
TryReadGlobalVar(name, var value) : attempts to read variable of given name, if defined places the value in value and returns True, otherwise returns False

WriteGlobalVar(name, value, [expiration]) : writes value into the variable of given name, with an optional auto-expiration (in seconds)

IncrementGlobalVar(name, delta = 1) : adds delta to the variable of given name and returns the resulting value

DeleteGlobalVar(name) : deletes the variable of given name

CleanupGlobalVars(filter = ‘*’) : delete variables matching the specified filter (wildcards ‘*’ and ‘?’ are supported). Memory is compacted if relevant. An empty string as filter will essentially just run a compaction operation.

GlobalVarNames : returns an array of string that holds the names of all variables

SaveGlobalVarsToString : returns a streamed persistence of all global vars

LoadGlobalVarsFromString : loads a streamed persistence of all global vars

 

Global Queues: are named chains of values which can be used both as a LIFO and FIFO queues. Writing or reading from a queue is thread-safe and atomic.

While they’re quite self-sufficient on their own, you’ll usually want to access them through a minimal wrapper functions that’ll handle namespaces.

Here is the complete list of Global Queues functions:

GlobalQueuePush(name, value) : adds value at the tail of the queue of given name
GlobalQueueInsert(name, value) : adds value at the head of the queue of given name
GlobalQueuePull(name, var value) : removes a value from the head of the queue of given name, places it in value and returns True. If the queue is empty, returns False
GlobalQueuePop(name, var value) : removes a value from the tail of the queue of given name, places it in value and returns True. If the queue is empty, returns False
GlobalQueueLength(name) : returns the length of the queue of given name
CleanupGlobalQueues : delete queues matching the specified filter (wildcards ‘*’ and ‘?’ are supported)


 



#2 Dany

Dany
  • Members
  • 127 posts

Posted 27 May 2016 - 03:27 PM

Brilliant. OK. But you do not write  where this comes from. Unit? ECMA? SMS JSCodegen?



#3 Laksekjønn

Laksekjønn
  • Members
  • 440 posts

Posted 27 May 2016 - 04:31 PM

The Smart Pascal dialect stems from the DWScript language where this background info comes from. You have those pseudo methods is smart, but does nothing.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users