From 566a3e0bd2077054df1d681326dc9efdc41e75e5 Mon Sep 17 00:00:00 2001 From: Brett Langdon Date: Sun, 25 Nov 2012 23:11:58 -0500 Subject: [PATCH] updated readme, renamed example dir to examples --- README.md | 45 +++++++++++------------- {example => examples}/config/config.lua | 0 {example => examples}/config/index.js | 0 {example => examples}/constants/index.js | 0 {example => examples}/functions/index.js | 0 {example => examples}/simple/index.js | 0 6 files changed, 21 insertions(+), 24 deletions(-) rename {example => examples}/config/config.lua (100%) rename {example => examples}/config/index.js (100%) rename {example => examples}/constants/index.js (100%) rename {example => examples}/functions/index.js (100%) rename {example => examples}/simple/index.js (100%) diff --git a/README.md b/README.md index 2a6276a..bbc35e2 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The `NodeLua` module itself contains the objects `LuaObject`, `LuaFunction`, as var lua = new nodelua.LuaObject() ``` -#### STATUS +#### -- STATUS `STATUS` is an object that contains the constants for values returned by `LuaObject.status()`. `nodelua.STATUS` conatins the following constants: @@ -33,7 +33,7 @@ var lua = new nodelua.LuaObject() * `ERRMEM: 4` * `ERRERR: 5` -#### GC +#### -- GC `GC` is an object of constants used for controlling the lua garbage collector. `nodelua.GC` conatins the following constants: @@ -46,7 +46,7 @@ var lua = new nodelua.LuaObject() * `SETPAUSE: 6` * `SETSTEPMUL: 7` -#### INFO +#### -- INFO `INFO` is an object containing constants with information about the version of lua you are using. `nodelua.INFO` contains the following constants: @@ -61,7 +61,7 @@ The `LuaFunction` is used to initialize a javascript function for use by lua. One caveat to using `LuaFunction`s and multiple `LuaObject`s is that `LuaFunction`s regardless of which `LuaObject` they are registered with are visable to ALL `LuaObject`s. -#### LuaFunction(func_name, func) +#### -- LuaFunction(func_name, func) The constructor for `LuaFunction` requires the `func_name` to use from within Lua (`nodelua('name')`) as well as the function itself `func`. ```javascript var func = new nodelua.LuaFunction('test', function(){ @@ -70,38 +70,38 @@ var func = new nodelua.LuaFunction('test', function(){ }); ``` -#### name +#### -- name The `name` property of the `LuaFunction` is exposed, but it cannot be changed. ### LuaObject The `LuaObject` is an object wrapper around a `lua_State` instance. -#### doFile(file_name) +#### -- doFile(file_name) The `doFile` method is used to load and execute lua code stored in `file_name`. ```javascript lua.doFile('test.lua'); ``` -#### doString(lua_code) +#### -- doString(lua_code) The `doString` method is the same as `doFile` except the code is loaded from `lua_code` rather than from a file. ```javascript lua.doString("print('Hello, Lua')"); ``` -#### setGlobal(name, value) +#### -- setGlobal(name, value) The `setGlobal` method is used to provide lua with the global variable `name` containing the value `value`. ```javascript lua.setGlobal('test', 'value'); ``` -#### getGlobal(name) +#### -- getGlobal(name) The `getGlobal` method is used to retrieve either a value set by `setGlobal` or a global variable in any lua code that has been run. ```javascript console.log(lua.getGlobal('test')); ``` -#### registerFunction(func) +#### -- registerFunction(func) `registerFunction` is used to expose a `LuaFunction` `func` to lua. ```javascript var func = new nodelua.LuaFunction('add_them', function(a, b){ @@ -118,7 +118,7 @@ nodelua('add_them', 3, 5) ``` All `LuaFunction`s registered with `registerFunction` is registered globally for all `LuaObject`s regardless of which object is used to register it. -#### status() +#### -- 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`. ```javascript if(lua.status() == nodelua.STATUS.ERRSYNTAX){ @@ -126,60 +126,57 @@ if(lua.status() == nodelua.STATUS.ERRSYNTAX){ } ``` -#### collectGarbage(GC_CODE) +#### -- collectGarbage(GC_CODE) `collectGarbage` is used to control the lua garbage collector. `GC_CODE` should be one of the codes taken from `nodelua.GC`. ```javascript lua.collectGarbage(nodelua.GC.COLLECT); ``` -#### push(value) +#### -- push(value) Push `value` onto the Lua stack. ```javascript lua.push(5); ``` -#### pop(num) +#### -- pop(num) Pop `num` items from the stack. Default is 1. ```javascript lua.pop(5); ``` -#### getTop() +#### -- getTop() Return the number of elements on the Lua stack. ```javascript var num = lua.getTop(); ``` -#### setTop(index) +#### -- setTop(index) Set the top of the Lua stack to `index`. ```javascript lua.setTop(3); ``` -#### replace(index) +#### -- replace(index) Replaces the top stack element into the specified `index` ```javascript lua.repalce(3); ``` -#### close() +#### -- close() `close` should be used whenever you have finished using a `LuaObject`. This will simply call `lua_close` on the `lua_State` for that object. ## Example -See test/test.js - +See `./examples/`. ```javascript var nodelua = require('nodelua'); var lua = new nodelua.LuaObject(); -lua.registerFunction('add_them', function(a, b){ - console.dir(a+b); +var func = new nodelua.LuaFunction('add_them', function(a, b){ + return a + b; }); lua.doFile('some_file.lua'); console.dir(lua.getGlobal('some_var')); - -lua.close() ``` ## License diff --git a/example/config/config.lua b/examples/config/config.lua similarity index 100% rename from example/config/config.lua rename to examples/config/config.lua diff --git a/example/config/index.js b/examples/config/index.js similarity index 100% rename from example/config/index.js rename to examples/config/index.js diff --git a/example/constants/index.js b/examples/constants/index.js similarity index 100% rename from example/constants/index.js rename to examples/constants/index.js diff --git a/example/functions/index.js b/examples/functions/index.js similarity index 100% rename from example/functions/index.js rename to examples/functions/index.js diff --git a/example/simple/index.js b/examples/simple/index.js similarity index 100% rename from example/simple/index.js rename to examples/simple/index.js