diff --git a/src/luaobject.cc b/src/luaobject.cc index 17434f2..acef293 100644 --- a/src/luaobject.cc +++ b/src/luaobject.cc @@ -4,30 +4,7 @@ #include "luaobject.h" using namespace v8; - -LuaObject::LuaObject() {}; -LuaObject::~LuaObject() {}; - -std::map > functions; - void LuaObject::Init(Handle target) { - // Prepare constructor template - Local tpl = FunctionTemplate::New(New); - tpl->SetClassName(String::NewSymbol("LuaObject")); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - // Prototype - tpl->PrototypeTemplate()->Set(String::NewSymbol("doString"), - FunctionTemplate::New(DoString)->GetFunction()); - tpl->PrototypeTemplate()->Set(String::NewSymbol("getGlobal"), - FunctionTemplate::New(GetGlobal)->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()); tpl->PrototypeTemplate()->Set(String::NewSymbol("push"), FunctionTemplate::New(Push)->GetFunction()); tpl->PrototypeTemplate()->Set(String::NewSymbol("pop"), @@ -38,50 +15,8 @@ void LuaObject::Init(Handle target) { FunctionTemplate::New(SetTop)->GetFunction()); tpl->PrototypeTemplate()->Set(String::NewSymbol("replace"), FunctionTemplate::New(Replace)->GetFunction()); - - Persistent constructor = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("LuaObject"), constructor); -} - -Handle LuaObject::New(const Arguments& args) { - HandleScope scope; - - LuaObject* obj = new LuaObject(); - obj->lua_ = lua_open(); - luaL_openlibs(obj->lua_); - lua_register(obj->lua_, "nodelua", LuaObject::CallFunction); - obj->Wrap(args.This()); - - return args.This(); } - - -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::Push(const Arguments& args) { HandleScope scope; diff --git a/src/luaobject.h b/src/luaobject.h index a30411b..9245155 100644 --- a/src/luaobject.h +++ b/src/luaobject.h @@ -13,28 +13,11 @@ extern "C"{ } class LuaObject : public node::ObjectWrap { - public: - static void Init(v8::Handle target); - static int CallFunction(lua_State *L); - - private: - LuaObject(); - ~LuaObject(); - - static v8::Handle New(const v8::Arguments& args); - static v8::Handle DoString(const v8::Arguments& args); - static v8::Handle GetGlobal(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); static v8::Handle Push(const v8::Arguments& args); static v8::Handle Pop(const v8::Arguments& args); static v8::Handle GetTop(const v8::Arguments& args); static v8::Handle SetTop(const v8::Arguments& args); static v8::Handle Replace(const v8::Arguments& args); - - lua_State *lua_; }; #endif