|
|
@ -16,14 +16,10 @@ void LuaObject::Init(Handle<Object> target) { |
|
|
tpl->SetClassName(String::NewSymbol("LuaObject")); |
|
|
tpl->SetClassName(String::NewSymbol("LuaObject")); |
|
|
tpl->InstanceTemplate()->SetInternalFieldCount(1); |
|
|
tpl->InstanceTemplate()->SetInternalFieldCount(1); |
|
|
// Prototype
|
|
|
// Prototype
|
|
|
tpl->PrototypeTemplate()->Set(String::NewSymbol("doFile"), |
|
|
|
|
|
FunctionTemplate::New(DoFile)->GetFunction()); |
|
|
|
|
|
tpl->PrototypeTemplate()->Set(String::NewSymbol("doString"), |
|
|
tpl->PrototypeTemplate()->Set(String::NewSymbol("doString"), |
|
|
FunctionTemplate::New(DoString)->GetFunction()); |
|
|
FunctionTemplate::New(DoString)->GetFunction()); |
|
|
tpl->PrototypeTemplate()->Set(String::NewSymbol("getGlobal"), |
|
|
tpl->PrototypeTemplate()->Set(String::NewSymbol("getGlobal"), |
|
|
FunctionTemplate::New(GetGlobal)->GetFunction()); |
|
|
FunctionTemplate::New(GetGlobal)->GetFunction()); |
|
|
tpl->PrototypeTemplate()->Set(String::NewSymbol("setGlobal"), |
|
|
|
|
|
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"), |
|
|
tpl->PrototypeTemplate()->Set(String::NewSymbol("status"), |
|
|
@ -70,13 +66,13 @@ Handle<Value> LuaObject::Status(const Arguments& args){ |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
|
LuaObject* obj = ObjectWrap::Unwrap<LuaObject>(args.This()); |
|
|
LuaObject* obj = ObjectWrap::Unwrap<LuaObject>(args.This()); |
|
|
int status = lua_status(obj->lua_); |
|
|
int status = lua_status(obj->lua_); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return scope.Close(Number::New(status)); |
|
|
return scope.Close(Number::New(status)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Handle<Value> LuaObject::CollectGarbage(const Arguments& args){ |
|
|
Handle<Value> LuaObject::CollectGarbage(const Arguments& args){ |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(args.Length() < 1){ |
|
|
if(args.Length() < 1){ |
|
|
ThrowException(Exception::TypeError(String::New("Wrong number of arguments"))); |
|
|
ThrowException(Exception::TypeError(String::New("Wrong number of arguments"))); |
|
|
return scope.Close(Undefined()); |
|
|
return scope.Close(Undefined()); |
|
|
@ -86,7 +82,7 @@ Handle<Value> LuaObject::CollectGarbage(const Arguments& args){ |
|
|
ThrowException(Exception::TypeError(String::New("Argument 1 must be a number, try nodelua.GC"))); |
|
|
ThrowException(Exception::TypeError(String::New("Argument 1 must be a number, try nodelua.GC"))); |
|
|
return scope.Close(Undefined()); |
|
|
return scope.Close(Undefined()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LuaObject* obj = ObjectWrap::Unwrap<LuaObject>(args.This()); |
|
|
LuaObject* obj = ObjectWrap::Unwrap<LuaObject>(args.This()); |
|
|
int type = (int)args[0]->ToNumber()->Value(); |
|
|
int type = (int)args[0]->ToNumber()->Value(); |
|
|
int gc = lua_gc(obj->lua_, type, 0); |
|
|
int gc = lua_gc(obj->lua_, type, 0); |
|
|
@ -94,28 +90,6 @@ Handle<Value> LuaObject::CollectGarbage(const Arguments& args){ |
|
|
return scope.Close(Number::New(gc)); |
|
|
return scope.Close(Number::New(gc)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Handle<Value> LuaObject::DoFile(const Arguments& args) { |
|
|
|
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
|
|
|
if(args.Length() < 1){ |
|
|
|
|
|
ThrowException(Exception::TypeError(String::New("Wrong number of arguments"))); |
|
|
|
|
|
return scope.Close(Undefined()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char *file_name = get_str(args[0]); |
|
|
|
|
|
|
|
|
|
|
|
LuaObject* obj = ObjectWrap::Unwrap<LuaObject>(args.This()); |
|
|
|
|
|
if(luaL_dofile(obj->lua_, file_name)){ |
|
|
|
|
|
char buf[1000]; |
|
|
|
|
|
sprintf(buf, "Execution Of File %s Has Failed:\n%s\n", file_name, lua_tostring(obj->lua_, -1)); |
|
|
|
|
|
ThrowException(Exception::TypeError(String::New(buf))); |
|
|
|
|
|
return scope.Close(Undefined()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return scope.Close(Undefined()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> LuaObject::DoString(const Arguments& args) { |
|
|
Handle<Value> LuaObject::DoString(const Arguments& args) { |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
@ -157,24 +131,6 @@ Handle<Value> LuaObject::GetGlobal(const Arguments& args) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> LuaObject::SetGlobal(const Arguments& args) { |
|
|
|
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
|
|
|
if(args.Length() < 2){ |
|
|
|
|
|
ThrowException(Exception::TypeError(String::New("Wrong number of arguments"))); |
|
|
|
|
|
return scope.Close(Undefined()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char *global_name = get_str(args[0]); |
|
|
|
|
|
|
|
|
|
|
|
LuaObject* obj = ObjectWrap::Unwrap<LuaObject>(args.This()); |
|
|
|
|
|
|
|
|
|
|
|
push_value_to_lua(obj->lua_, args[1]); |
|
|
|
|
|
lua_setglobal(obj->lua_, global_name); |
|
|
|
|
|
|
|
|
|
|
|
return scope.Close(Undefined()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> LuaObject::Push(const Arguments& args) { |
|
|
Handle<Value> LuaObject::Push(const Arguments& args) { |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
@ -300,7 +256,7 @@ int LuaObject::CallFunction(lua_State *L){ |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
push_value_to_lua(L, ret_val); |
|
|
push_value_to_lua(L, ret_val); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |