52 |
// Helper routines |
// Helper routines |
53 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |
54 |
|
|
55 |
|
using enigma::Value; |
56 |
|
|
57 |
static void |
static void |
58 |
push_value(lua_State *L, const tools::Value &val) |
push_value(lua_State *L, const Value &val) |
59 |
{ |
{ |
|
using tools::Value; |
|
|
|
|
60 |
switch (val.get_type()) { |
switch (val.get_type()) { |
61 |
case Value::NIL: lua_pushnil(L); break; |
case Value::NIL: lua_pushnil(L); break; |
62 |
case Value::DOUBLE: lua_pushnumber(L, to_double(val)); break; |
case Value::DOUBLE: lua_pushnumber(L, to_double(val)); break; |
63 |
case Value::STRING: lua_pushstring(L, to_string(val)); break; |
case Value::STRING: lua_pushstring(L, to_string(val)); break; |
|
case Value::VECTOR3: assert(0); break; // FIXME |
|
64 |
} |
} |
65 |
} |
} |
66 |
|
|
67 |
static tools::Value |
static Value |
68 |
to_value(lua_State *L, int idx) |
to_value(lua_State *L, int idx) |
69 |
{ |
{ |
70 |
switch (lua_type(L, idx)) { |
switch (lua_type(L, idx)) { |
71 |
case LUA_TNIL: return tools::Value(); |
case LUA_TNIL: return Value(); |
72 |
case LUA_TNUMBER: return tools::Value(lua_tonumber(L,idx)); |
case LUA_TNUMBER: return Value(lua_tonumber(L,idx)); |
73 |
case LUA_TSTRING: return tools::Value(lua_tostring(L,idx)); |
case LUA_TSTRING: return Value(lua_tostring(L,idx)); |
74 |
default: lua_error(L,"Cannot convert type to Value."); |
default: lua_error(L,"Cannot convert type to Value."); |
75 |
} |
} |
76 |
return tools::Value(); |
return Value(); |
77 |
} |
} |
78 |
|
|
79 |
static bool |
static bool |
152 |
return 0; |
return 0; |
153 |
} |
} |
154 |
|
|
155 |
const tools::Value *v = obj->get_attrib(key); |
const Value *v = obj->get_attrib(key); |
156 |
if (!v) { |
if (!v) { |
157 |
lua_error(L, "GetAttrib: unknown attribute"); |
lua_error(L, "GetAttrib: unknown attribute"); |
158 |
lua_pushnil(L); |
lua_pushnil(L); |
347 |
} |
} |
348 |
|
|
349 |
int |
int |
350 |
lua::CallFunc(const char *funcname, const tools::Value& arg) |
lua::CallFunc(const char *funcname, const Value& arg) |
351 |
{ |
{ |
352 |
lua_getglobal(state, funcname); |
lua_getglobal(state, funcname); |
353 |
push_value(state, arg); |
push_value(state, arg); |