Browse Source

added status and collectGarbage methods

v0.1.x
Brett Langdon 13 years ago
parent
commit
24de83f517
2 changed files with 34 additions and 0 deletions
  1. +32
    -0
      src/luaobject.cc
  2. +2
    -0
      src/luaobject.h

+ 32
- 0
src/luaobject.cc View File

@ -26,6 +26,10 @@ void LuaObject::Init(Handle<Object> target) {
FunctionTemplate::New(SetGlobal)->GetFunction()); FunctionTemplate::New(SetGlobal)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("registerFunction"), tpl->PrototypeTemplate()->Set(String::NewSymbol("registerFunction"),
FunctionTemplate::New(RegisterFunction)->GetFunction()); FunctionTemplate::New(RegisterFunction)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("status"),
FunctionTemplate::New(Status)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("collectGarbage"),
FunctionTemplate::New(CollectGarbage)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("close"), tpl->PrototypeTemplate()->Set(String::NewSymbol("close"),
FunctionTemplate::New(Close)->GetFunction()); FunctionTemplate::New(Close)->GetFunction());
@ -53,6 +57,34 @@ Handle<Value> LuaObject::Close(const Arguments& args){
return scope.Close(Undefined()); return scope.Close(Undefined());
} }
Handle<Value> LuaObject::Status(const Arguments& args){
HandleScope scope;
LuaObject* obj = ObjectWrap::Unwrap<LuaObject>(args.This());
int status = lua_status(obj->lua_);
return scope.Close(Number::New(status));
}
Handle<Value> LuaObject::CollectGarbage(const Arguments& args){
HandleScope scope;
if(args.Length() < 1){
ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
return scope.Close(Undefined());
}
if(!args[0]->IsNumber()){
ThrowException(Exception::TypeError(String::New("Argument 1 must be a number, try nodelua.GC")));
return scope.Close(Undefined());
}
LuaObject* obj = ObjectWrap::Unwrap<LuaObject>(args.This());
int type = (int)args[0]->ToNumber()->Value();
int gc = lua_gc(obj->lua_, type, 0);
return scope.Close(Number::New(gc));
}
Handle<Value> LuaObject::DoFile(const Arguments& args) { Handle<Value> LuaObject::DoFile(const Arguments& args) {
HandleScope scope; HandleScope scope;


+ 2
- 0
src/luaobject.h View File

@ -25,6 +25,8 @@ class LuaObject : public node::ObjectWrap {
static v8::Handle<v8::Value> GetGlobal(const v8::Arguments& args); static v8::Handle<v8::Value> GetGlobal(const v8::Arguments& args);
static v8::Handle<v8::Value> SetGlobal(const v8::Arguments& args); static v8::Handle<v8::Value> SetGlobal(const v8::Arguments& args);
static v8::Handle<v8::Value> RegisterFunction(const v8::Arguments& args); static v8::Handle<v8::Value> RegisterFunction(const v8::Arguments& args);
static v8::Handle<v8::Value> Status(const v8::Arguments& args);
static v8::Handle<v8::Value> CollectGarbage(const v8::Arguments& args);
static v8::Handle<v8::Value> Close(const v8::Arguments& args); static v8::Handle<v8::Value> Close(const v8::Arguments& args);
lua_State *lua_; lua_State *lua_;


Loading…
Cancel
Save