From 24de83f517971d9fbb82f1fe1c4645fb68aa6033 Mon Sep 17 00:00:00 2001 From: Brett Langdon Date: Sun, 25 Nov 2012 18:11:02 -0500 Subject: [PATCH] added status and collectGarbage methods --- src/luaobject.cc | 32 ++++++++++++++++++++++++++++++++ src/luaobject.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/luaobject.cc b/src/luaobject.cc index 38b7279..068626a 100644 --- a/src/luaobject.cc +++ b/src/luaobject.cc @@ -26,6 +26,10 @@ void LuaObject::Init(Handle target) { FunctionTemplate::New(SetGlobal)->GetFunction()); tpl->PrototypeTemplate()->Set(String::NewSymbol("registerFunction"), 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"), FunctionTemplate::New(Close)->GetFunction()); @@ -53,6 +57,34 @@ Handle LuaObject::Close(const Arguments& args){ return scope.Close(Undefined()); } +Handle LuaObject::Status(const Arguments& args){ + HandleScope scope; + LuaObject* obj = ObjectWrap::Unwrap(args.This()); + int status = lua_status(obj->lua_); + + return scope.Close(Number::New(status)); +} + +Handle 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(args.This()); + int type = (int)args[0]->ToNumber()->Value(); + int gc = lua_gc(obj->lua_, type, 0); + + return scope.Close(Number::New(gc)); +} + Handle LuaObject::DoFile(const Arguments& args) { HandleScope scope; diff --git a/src/luaobject.h b/src/luaobject.h index d7e9e07..b4213a1 100644 --- a/src/luaobject.h +++ b/src/luaobject.h @@ -25,6 +25,8 @@ class LuaObject : public node::ObjectWrap { static v8::Handle GetGlobal(const v8::Arguments& args); static v8::Handle SetGlobal(const v8::Arguments& args); static v8::Handle RegisterFunction(const v8::Arguments& args); + static v8::Handle Status(const v8::Arguments& args); + static v8::Handle CollectGarbage(const v8::Arguments& args); static v8::Handle Close(const v8::Arguments& args); lua_State *lua_;