Browse Source

updated readme, renamed example dir to examples

v0.1.x
Brett Langdon 13 years ago
parent
commit
566a3e0bd2
6 changed files with 21 additions and 24 deletions
  1. +21
    -24
      README.md
  2. +0
    -0
      examples/config/config.lua
  3. +0
    -0
      examples/config/index.js
  4. +0
    -0
      examples/constants/index.js
  5. +0
    -0
      examples/functions/index.js
  6. +0
    -0
      examples/simple/index.js

+ 21
- 24
README.md View File

@ -23,7 +23,7 @@ The `NodeLua` module itself contains the objects `LuaObject`, `LuaFunction`, as
var lua = new nodelua.LuaObject() var lua = new nodelua.LuaObject()
``` ```
#### STATUS
#### -- STATUS
`STATUS` is an object that contains the constants for values returned by `LuaObject.status()`. `STATUS` is an object that contains the constants for values returned by `LuaObject.status()`.
`nodelua.STATUS` conatins the following constants: `nodelua.STATUS` conatins the following constants:
@ -33,7 +33,7 @@ var lua = new nodelua.LuaObject()
* `ERRMEM: 4` * `ERRMEM: 4`
* `ERRERR: 5` * `ERRERR: 5`
#### GC
#### -- GC
`GC` is an object of constants used for controlling the lua garbage collector. `GC` is an object of constants used for controlling the lua garbage collector.
`nodelua.GC` conatins the following constants: `nodelua.GC` conatins the following constants:
@ -46,7 +46,7 @@ var lua = new nodelua.LuaObject()
* `SETPAUSE: 6` * `SETPAUSE: 6`
* `SETSTEPMUL: 7` * `SETSTEPMUL: 7`
#### INFO
#### -- INFO
`INFO` is an object containing constants with information about the version of lua you are using. `INFO` is an object containing constants with information about the version of lua you are using.
`nodelua.INFO` contains the following constants: `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` 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. 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`. The constructor for `LuaFunction` requires the `func_name` to use from within Lua (`nodelua('name')`) as well as the function itself `func`.
```javascript ```javascript
var func = new nodelua.LuaFunction('test', function(){ 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. The `name` property of the `LuaFunction` is exposed, but it cannot be changed.
### LuaObject ### LuaObject
The `LuaObject` is an object wrapper around a `lua_State` instance. 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`. The `doFile` method is used to load and execute lua code stored in `file_name`.
```javascript ```javascript
lua.doFile('test.lua'); 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. The `doString` method is the same as `doFile` except the code is loaded from `lua_code` rather than from a file.
```javascript ```javascript
lua.doString("print('Hello, Lua')"); 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`. The `setGlobal` method is used to provide lua with the global variable `name` containing the value `value`.
```javascript ```javascript
lua.setGlobal('test', 'value'); 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. 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 ```javascript
console.log(lua.getGlobal('test')); console.log(lua.getGlobal('test'));
``` ```
#### registerFunction(func)
#### -- registerFunction(func)
`registerFunction` is used to expose a `LuaFunction` `func` to lua. `registerFunction` is used to expose a `LuaFunction` `func` to lua.
```javascript ```javascript
var func = new nodelua.LuaFunction('add_them', function(a, b){ 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. 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`. `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 ```javascript
if(lua.status() == nodelua.STATUS.ERRSYNTAX){ 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`. `collectGarbage` is used to control the lua garbage collector. `GC_CODE` should be one of the codes taken from `nodelua.GC`.
```javascript ```javascript
lua.collectGarbage(nodelua.GC.COLLECT); lua.collectGarbage(nodelua.GC.COLLECT);
``` ```
#### push(value)
#### -- push(value)
Push `value` onto the Lua stack. Push `value` onto the Lua stack.
```javascript ```javascript
lua.push(5); lua.push(5);
``` ```
#### pop(num)
#### -- pop(num)
Pop `num` items from the stack. Default is 1. Pop `num` items from the stack. Default is 1.
```javascript ```javascript
lua.pop(5); lua.pop(5);
``` ```
#### getTop()
#### -- getTop()
Return the number of elements on the Lua stack. Return the number of elements on the Lua stack.
```javascript ```javascript
var num = lua.getTop(); var num = lua.getTop();
``` ```
#### setTop(index)
#### -- setTop(index)
Set the top of the Lua stack to `index`. Set the top of the Lua stack to `index`.
```javascript ```javascript
lua.setTop(3); lua.setTop(3);
``` ```
#### replace(index)
#### -- replace(index)
Replaces the top stack element into the specified `index` Replaces the top stack element into the specified `index`
```javascript ```javascript
lua.repalce(3); 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. `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 ## Example
See test/test.js
See `./examples/`.
```javascript ```javascript
var nodelua = require('nodelua'); var nodelua = require('nodelua');
var lua = new nodelua.LuaObject(); 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'); lua.doFile('some_file.lua');
console.dir(lua.getGlobal('some_var')); console.dir(lua.getGlobal('some_var'));
lua.close()
``` ```
## License ## License


example/config/config.lua → examples/config/config.lua View File


example/config/index.js → examples/config/index.js View File


example/constants/index.js → examples/constants/index.js View File


example/functions/index.js → examples/functions/index.js View File


example/simple/index.js → examples/simple/index.js View File


Loading…
Cancel
Save