This is the synchronous version of `doString`, any value returned from the script is returned.
```javascript
var ret_value = lua.doString("return 5");
console.dir(ret_value);
```
#### -- setGlobal(name, value)
@ -104,35 +118,46 @@ The `getGlobal` method is used to retrieve either a value set by `setGlobal` or
console.log(lua.getGlobal('test'));
```
#### -- registerFunction(func)
`registerFunction` is used to expose a `LuaFunction``func` to lua.
#### -- registerFunction(name, func)
`registerFunction` is used to expose a javascript function to lua.
```javascript
var func = new nodelua.LuaFunction('add_them', function(a, b){
console.log(a+b);
lua.registerFunction('add_them', function(a, b){
return a + b;
});
lua.registerFunction(func);
lua.doString('nodelua("add_them", 2, 4)');
var ret_value = lua.doStringSync('return add_them(2, 4)');
console.dir(ret_value);
```
There are a few caveats with `registerFunction`.
For starters in order to invoke the javascript function from within lua you must use an exposed `nodelua` function as opposed to using the functions registered `name`.
```lua
nodelua('add_them', 3, 5)
#### -- status(callback)
`status` will return the current status code for lua. The result can be `0` for normal or one of the error codes in `nodelua.STATUS`.
```javascript
lua.status(function(code){
if(code == nodelua.STATUS.ERRSYNTAX){
console.error('Lua Syntax Error');
}
});
```
All `LuaFunction`s registered with `registerFunction` is registered globally for all `LuaObject`s regardless of which object is used to register it.
#### -- status()
`status` will return the current status code for lua. The result can be `0` for normal or one of the error codes in `nodelua.STATUS`.
#### -- statusSync()
This is the synchronous version of `status`
```javascript
if(lua.status() == nodelua.STATUS.ERRSYNTAX){
console.error('Lua Syntax Error');
}
var code = lua.statusSync();
console.dir(code);
```
#### -- collectGarbage(GC_CODE)
#### -- collectGarbage(GC_CODE, callback)
`collectGarbage` is used to control the lua garbage collector. `GC_CODE` should be one of the codes taken from `nodelua.GC`.