Browse Source

added support for setting/getting boolean globals

v0.1.x
Brett Langdon 13 years ago
parent
commit
3c0a007b34
3 changed files with 7 additions and 2 deletions
  1. +5
    -0
      src/luaobject.cc
  2. +1
    -1
      test/test.js
  3. +1
    -1
      test/test.lua

+ 5
- 0
src/luaobject.cc View File

@ -97,6 +97,8 @@ Handle<Value> LuaObject::GetGlobal(const Arguments& args) {
return scope.Close(Number::New((int)lua_tonumber(obj->lua_, -1)));
}else if(lua_isstring(obj->lua_, -1)){
return scope.Close(String::New((char *)lua_tostring(obj->lua_, -1)));
}else if(lua_isboolean(obj->lua_, -1)){
return scope.Close(Boolean::New((int)lua_toboolean(obj->lua_, -1)));
}
return scope.Close(Undefined());
@ -130,6 +132,9 @@ Handle<Value> LuaObject::SetGlobal(const Arguments& args) {
}else if(args[1]->IsNumber()){
int value = args[1]->ToNumber()->Value();
lua_pushinteger(obj->lua_, value);
}else if(args[1]->IsBoolean()){
int value = (int)args[1]->ToBoolean()->Value();
lua_pushboolean(obj->lua_, value);
}else{
lua_pushnil(obj->lua_);
}


+ 1
- 1
test/test.js View File

@ -9,7 +9,7 @@ lua.doFile(test_file);
lua.setGlobal("test", "value");
lua.setGlobal("one", 1);
lua.setGlobal("two", "two");
lua.setGlobal("two", true);
lua.setGlobal("none", null);
console.dir(lua.getGlobal("one"));


+ 1
- 1
test/test.lua View File

@ -1 +1 @@
print "Hello, Lua"
print "Hello, Lua"

Loading…
Cancel
Save