diff --git a/examples/config/index.js b/examples/config/index.js index 281b0a8..2d41054 100644 --- a/examples/config/index.js +++ b/examples/config/index.js @@ -1,7 +1,7 @@ var path = require('path'); var nodelua = require('../../'); -var lua = new nodelua.LuaObject(); +var lua = new nodelua.LuaState('config'); // set a default value lua.setGlobal('js_value', 'this is js_value'); @@ -9,9 +9,9 @@ console.log('js_value: ' + lua.getGlobal('js_value')); console.log('Processing Config.lua'); var config = path.resolve(__dirname, 'config.lua'); -lua.doFile(config); - -console.log('js_value: ' + lua.getGlobal('js_value')); -console.log('val_one: ' + lua.getGlobal('val_one')); -console.log('val_two: ' + lua.getGlobal('val_two')); -console.log('val_three: ' + lua.getGlobal('val_three')); \ No newline at end of file +lua.doFile(config, function(){ + console.log('js_value: ' + lua.getGlobal('js_value')); + console.log('val_one: ' + lua.getGlobal('val_one')); + console.log('val_two: ' + lua.getGlobal('val_two')); + console.log('val_three: ' + lua.getGlobal('val_three')); + }); \ No newline at end of file diff --git a/examples/files/index.js b/examples/files/index.js new file mode 100644 index 0000000..a72cff1 --- /dev/null +++ b/examples/files/index.js @@ -0,0 +1,14 @@ +var nodelua = require('../../'); + +var luastate = new nodelua.LuaState('files'); + +luastate.setGlobal('test', 'some value'); + +var file_name = __dirname + '/test.lua'; +luastate.doFile(file_name, function(err, ret){ + if(!err && ret){ + console.log(ret); + } else{ + console.error(err); + } + }); \ No newline at end of file diff --git a/examples/files/test.lua b/examples/files/test.lua new file mode 100644 index 0000000..1eefc52 --- /dev/null +++ b/examples/files/test.lua @@ -0,0 +1 @@ +return "lua:" .. test \ No newline at end of file diff --git a/examples/functions/index.js b/examples/functions/index.js index dc278f2..fae5e8f 100644 --- a/examples/functions/index.js +++ b/examples/functions/index.js @@ -1,22 +1,13 @@ var nodelua = require('../../'); -var lua = new nodelua.LuaObject(); +var lua = new nodelua.LuaState('functions'); -var add_them = new nodelua.LuaFunction('add_them', function(a, b){ - console.log('Adding ' + a + ' and ' + b + ' in js'); +lua.registerFunction('add', function(a, b){ return a + b; }); -lua.registerFunction(add_them); -// Functionas are registered globally -// for all LuaObjects -var lua_two = new nodelua.LuaObject(); -lua_two.doString("print('Result in Lua: ' .. nodelua('add_them', 10, 5))"); +lua.doStringSync("print('Result in Lua: ' .. add(10, 5))"); -var subtract_them = new nodelua.LuaFunction('subtract_them', function(a, b){ - console.log('Subtracting ' + a + ' and ' + b + ' in js'); - return a - b; - }); - -lua_two.registerFunction(subtract_them); -lua.doString("print('Result in Lua: ' .. nodelua('subtract_them', 10, 5))"); \ No newline at end of file +var lua_two = new nodelua.LuaState('two'); +// this will throw an error +lua_two.doStringSync("add(10, 5)"); \ No newline at end of file diff --git a/examples/simple/index.js b/examples/simple/index.js index 99a8e6c..9585cf2 100644 --- a/examples/simple/index.js +++ b/examples/simple/index.js @@ -1,11 +1,11 @@ var nodelua = require('../../'); -var lua = new nodelua.LuaObject(); +var lua = new nodelua.LuaState('simple'); lua.setGlobal('js_value', 500); -lua.doString('print(js_value)'); - -lua.doString('js_value = "something new"'); - -console.dir(lua.getGlobal('js_value')); \ No newline at end of file +lua.doString('print("js_value: " .. js_value)', function(){ + lua.doString('js_value = "something new"', function(){ + console.log('js_value: ' + lua.getGlobal('js_value')); + }); + }); \ No newline at end of file