/[enigma]/enigma/src/lua.cc
ViewVC logotype

Diff of /enigma/src/lua.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by mhawlisch, Fri Jan 17 16:10:26 2003 UTC revision 1.4 by dheck, Thu Jan 23 22:41:00 2003 UTC
# Line 52  namespace lua Line 52  namespace lua
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
# Line 153  en_get_attrib(lua_State *L) Line 152  en_get_attrib(lua_State *L)
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);
# Line 348  lua::RegisterFuncs(CFunction *funcs) Line 347  lua::RegisterFuncs(CFunction *funcs)
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);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26