diff --git a/binding.gyp b/binding.gyp index 195fa89..5d154c3 100644 --- a/binding.gyp +++ b/binding.gyp @@ -8,7 +8,6 @@ }, "sources": [ "src/utils.cc", - "src/luafunction.cc", "src/luastate.cc", "src/nodelua.cc" ], diff --git a/src/luafunction.cc b/src/luafunction.cc deleted file mode 100644 index 4e078c4..0000000 --- a/src/luafunction.cc +++ /dev/null @@ -1,60 +0,0 @@ -#define BUILDING_NODELUA -#include -#include "luafunction.h" -#include "utils.h" - -using namespace v8; - -LuaFunction::LuaFunction() {}; -LuaFunction::~LuaFunction() {}; - -void LuaFunction::Init(Handle target) { - // Prepare constructor template - Local tpl = FunctionTemplate::New(New); - tpl->SetClassName(String::NewSymbol("LuaFunction")); - tpl->InstanceTemplate()->SetInternalFieldCount(2); - tpl->InstanceTemplate()->SetAccessor(String::New("name"), GetName, SetName); - - Persistent constructor = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("LuaFunction"), constructor); -} - -LuaFunction* LuaFunction::unwrap(Handle handle){ - return ObjectWrap::Unwrap(handle); -} - -Handle LuaFunction::New(const Arguments& args) { - HandleScope scope; - - if(args.Length() < 2){ - ThrowException(Exception::TypeError(String::New("Must have 2 arguments"))); - return scope.Close(Undefined()); - } - - if(!args[0]->IsString()){ - ThrowException(Exception::TypeError(String::New("Argument 1 must be a string"))); - return scope.Close(Undefined()); - } - - if(!args[1]->IsFunction()){ - ThrowException(Exception::TypeError(String::New("Argument 2 must be a function"))); - return scope.Close(Undefined()); - } - - LuaFunction* obj = new LuaFunction(); - obj->func_name = get_str(args[0]); - obj->func_def_ = Persistent::New(Handle::Cast(args[1])); - obj->Wrap(args.This()); - - return args.This(); -} - -Handle LuaFunction::GetName(Local property, const AccessorInfo &info) { - HandleScope scope; - - LuaFunction* obj = ObjectWrap::Unwrap(info.This()); - return scope.Close(String::New(obj->func_name)); -} - -void LuaFunction::SetName(Local property, Local value, const AccessorInfo& info) { -} diff --git a/src/luafunction.h b/src/luafunction.h deleted file mode 100644 index 28d05eb..0000000 --- a/src/luafunction.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef LUAFUNCTION_H -#define LUAFUNCTION_H - -#include - -extern "C"{ -#include -#include -#include -} - -class LuaFunction : public node::ObjectWrap { - public: - static void Init(v8::Handle target); - static LuaFunction* unwrap(v8::Handle handle); - - char *func_name; - v8::Persistent func_def_; - private: - LuaFunction(); - ~LuaFunction(); - - static v8::Handle New(const v8::Arguments& args); - static v8::Handle GetName(v8::Local property, const v8::AccessorInfo &info); - static void SetName(v8::Local property, v8::Local value, const v8::AccessorInfo& info); -}; - -#endif diff --git a/src/luaobject.cc b/src/luaobject.cc deleted file mode 100644 index acef293..0000000 --- a/src/luaobject.cc +++ /dev/null @@ -1,91 +0,0 @@ -#define BUILDING_NODELUA -#include -#include -#include "luaobject.h" - -using namespace v8; -void LuaObject::Init(Handle target) { - tpl->PrototypeTemplate()->Set(String::NewSymbol("push"), - FunctionTemplate::New(Push)->GetFunction()); - tpl->PrototypeTemplate()->Set(String::NewSymbol("pop"), - FunctionTemplate::New(Pop)->GetFunction()); - tpl->PrototypeTemplate()->Set(String::NewSymbol("getTop"), - FunctionTemplate::New(GetTop)->GetFunction()); - tpl->PrototypeTemplate()->Set(String::NewSymbol("setTop"), - FunctionTemplate::New(SetTop)->GetFunction()); - tpl->PrototypeTemplate()->Set(String::NewSymbol("replace"), - FunctionTemplate::New(Replace)->GetFunction()); -} - -Handle LuaObject::Push(const Arguments& args) { - HandleScope scope; - - if(args.Length() < 1){ - ThrowException(Exception::TypeError(String::New("Wrong number of arguments"))); - return scope.Close(Undefined()); - } - - LuaObject* obj = ObjectWrap::Unwrap(args.This()); - - push_value_to_lua(obj->lua_, args[0]); - - return scope.Close(Undefined()); -} - -Handle LuaObject::Pop(const Arguments& args) { - HandleScope scope; - - int pop_n = 1; - if(args.Length() > 0 && args[0]->IsNumber()){ - pop_n = (int)args[0]->ToNumber()->Value(); - } - - LuaObject* obj = ObjectWrap::Unwrap(args.This()); - lua_pop(obj->lua_, pop_n); - - return scope.Close(Undefined()); -} - -Handle LuaObject::GetTop(const Arguments& args) { - HandleScope scope; - - LuaObject* obj = ObjectWrap::Unwrap(args.This()); - int n = lua_gettop(obj->lua_); - - return scope.Close(Number::New(n)); -} - -Handle LuaObject::SetTop(const Arguments& args) { - HandleScope scope; - - int set_n = 0; - if(args.Length() > 0 && args[0]->IsNumber()){ - set_n = (int)args[0]->ToNumber()->Value(); - } - - LuaObject* obj = ObjectWrap::Unwrap(args.This()); - lua_settop(obj->lua_, set_n); - - return scope.Close(Undefined()); -} - -Handle LuaObject::Replace(const Arguments& args) { - HandleScope scope; - - if(args.Length() < 1){ - ThrowException(Exception::TypeError(String::New("Must Have 1 Argument"))); - return scope.Close(Undefined()); - } - - if(!args[0]->IsNumber()){ - ThrowException(Exception::TypeError(String::New("Argument 1 Must Be A Number"))); - return scope.Close(Undefined()); - } - - int index = (int)args[0]->ToNumber()->Value(); - - LuaObject* obj = ObjectWrap::Unwrap(args.This()); - lua_replace(obj->lua_, index); - - return scope.Close(Undefined()); -} diff --git a/src/luaobject.h b/src/luaobject.h deleted file mode 100644 index 9245155..0000000 --- a/src/luaobject.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef LUAOBJECT_H -#define LUAOBJECT_H - -#include - -#include "utils.h" -#include "luafunction.h" - -extern "C"{ -#include -#include -#include -} - -class LuaObject : public node::ObjectWrap { - 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); -}; - -#endif