LuaInterface 0.3
by parc on Jul.20, 2008, under Smalltalk
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"
src
nextPutAll: 'w = ' ; nextPutAll: aNumber printString ; cr.
"then we execue it which sets w to an integer value"
lua
doString: src contents.
"then we query the interpreter for the value of 'w'"
lua
getGlobalNamed: 'w'.
"and we check if its an integer and we check the value"
self
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. src nextPutAll: 'return w' ; cr. "we set the value in the new interpreter environment" lua 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).
Download: