LuaInterface 0.3

Several APIs added to set and retrieve values within the LUA environment. Several tests added.

Here are some examples, which are also included within the tests:

The idea of the first example shows, how a LUA script is executed (actually it is created within Smalltalk) and then the interpreter is asked for the value of a variable changed in that script.

| src aNumber |
  src := WriteStream on: String new.
  aNumber := Time now asMilliseconds.
  "First we create LUA souce which looks like w = 137482374"
    nextPutAll: 'w = ' ; nextPutAll: aNumber printString ; cr.
  "then we execue it which sets w to an integer value"
    doString: src contents.
  "then we query the interpreter for the value of 'w'"
    getGlobalNamed: 'w'.
  "and we check if its an integer and we check the value"
    assert: ((lua isNumber: -1) ) ;
    assert: ((lua toInteger: -1) = aNumber).

The next script sets the value of a LUA variable BEFORE executing LUA script. The script itselfs just returns the value set before executing the script:

| src aNumber |

aNumber := Time now asMilliseconds.
src := WriteStream on: String new.
  nextPutAll: 'return w' ; cr.
"we set the value in the new interpreter environment"
  pushInteger: aNumber ;
  setGlobalNamed: 'w' ;
"then we execute the code created above - simply returning the value again"
  doString: src contents.
"... and checking the results"
self assert: ((lua isNumber: -1) ).
self assert: ((lua toInteger: -1) = aNumber).



This entry was posted in Smalltalk and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s