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()
```
#### 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


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