Ejemplo n.º 1
0
void tLuaCOMEnumerator::registerLuaType(lua_State *L, const char *module)
{
  LUASTACK_SET(L);

  tLuaCOMEnumerator::module_name = module;

  luaCompat_newLuaType(L, 
    tLuaCOMEnumerator::module_name, 
    tLuaCOMEnumerator::type_name);

  luaCompat_newLuaType(L, 
    tLuaCOMEnumerator::module_name, 
    tLuaCOMEnumerator::pointer_type_name);

  luaCompat_pushTypeByName(L, 
    tLuaCOMEnumerator::module_name, 
    tLuaCOMEnumerator::type_name);

  lua_pushcfunction(L, tLuaCOMEnumerator::index);
  luaCompat_handleNoIndexEvent(L);

  lua_pop(L, 1);

  luaCompat_pushTypeByName(L, 
    tLuaCOMEnumerator::module_name, 
    tLuaCOMEnumerator::pointer_type_name);

  lua_pushcfunction(L, tLuaCOMEnumerator::garbagecollect);
  luaCompat_handleGCEvent(L);

  lua_pop(L, 1);
  
  LUASTACK_CLEAN(L, 0);
}
Ejemplo n.º 2
0
void tLuaObject::RegisterType(lua_State* L,
                              const char* type_name,
                              const char* pointer_type_name)
{
  LUASTACK_SET(L);

  luaCompat_moduleCreate(L, MODULENAME);
  lua_pop(L, 1);

  // Registers the table type and the pointer type
  luaCompat_newLuaType(L, MODULENAME, type_name);

  luaCompat_newLuaType(L, MODULENAME, pointer_type_name);

#ifdef LUA5
  // Registers the weak table to store the pairs
  // (pointer, LuaObject) to avoid duplication
  // of Lua objects. This step must be done
  // only once
  luaCompat_moduleGet(L, MODULENAME, INSTANCES_CACHE);

  if(lua_isnil(L, -1))
  {
    lua_pop(L, 1);
    // pushes tables
    lua_newtable(L);

    // pushes metatable and initializes it
    lua_newtable(L);
    lua_pushstring(L, "__mode");
    lua_pushstring(L, "v");
    lua_settable(L, -3);
    lua_setmetatable(L, -2);

    // stores in the registry
    luaCompat_moduleSet(L, MODULENAME, INSTANCES_CACHE);
  }
  else
    lua_pop(L, 1);
#endif  

  luaCompat_pushTypeByName(L, MODULENAME, type_name);

  lua_pushcfunction(L, tLuaObject::generic_index);
  luaCompat_handleNoIndexEvent(L);

  lua_pushcfunction(L, tLuaObject::generic_newindex);
  luaCompat_handleSettableEvent(L);

  lua_pop(L, 1);

  luaCompat_pushTypeByName(L, MODULENAME, pointer_type_name);

  lua_pushcfunction(L, tLuaObject::garbagecollect);
  luaCompat_handleGCEvent(L);

  lua_pop(L, 1);
  
  LUASTACK_CLEAN(L, 0);
}
Ejemplo n.º 3
0
LuaBeans::LuaBeans(lua_State *lua_state, const char* p_module, const char* name )
{
   char lua_name[50];

   this->mlist = NULL;

   L = lua_state;
   module_name = p_module;

   sprintf(lua_name,"%s",name);
   tag_name = tUtil::strdup(lua_name);
   luaCompat_newLuaType(L, module_name, tag_name);

   sprintf(lua_name,"%s_UDTAG",name);
   udtag_name = tUtil::strdup(lua_name);
   luaCompat_newLuaType(L, module_name, udtag_name);
}
Ejemplo n.º 4
0
void LuaBeans::createBeans(lua_State *L,
                           const char* p_module_name,
                           const char* name)
{
  LUASTACK_SET(L);

  char lua_name[500];

  module_name = tUtil::strdup(p_module_name);

  sprintf(lua_name, "%s" ,name);
  tag_name = tUtil::strdup(lua_name);
  luaCompat_newLuaType(L, module_name, tag_name);

  sprintf(lua_name,"%s_UDTAG",name);
  udtag_name = tUtil::strdup(lua_name);
  luaCompat_newLuaType(L, module_name, udtag_name);
  LUASTACK_CLEAN(L, 0);
}
Ejemplo n.º 5
0
void tLuaCOMEnumerator::registerLuaType(lua_State *L, const char *module)
{
  LUASTACK_SET(L);

  tStringBuffer module_name(module);
  // store value for later use (used to be DLL-static)
  tUtil::RegistrySetString(L, module_name_key, module_name);
  LUASTACK_CLEAN(L, 0);

  luaCompat_newLuaType(L, 
    module_name, 
    tLuaCOMEnumerator::type_name);

  luaCompat_newLuaType(L, 
    module_name, 
    tLuaCOMEnumerator::pointer_type_name);

  luaCompat_pushTypeByName(L, 
    module_name, 
    tLuaCOMEnumerator::type_name);

  lua_pushcfunction(L, tLuaCOMEnumerator::index);
  lua_setfield(L, -2, "__index");

  lua_pop(L, 1);

  luaCompat_pushTypeByName(L, 
    module_name, 
    tLuaCOMEnumerator::pointer_type_name);

  lua_pushcfunction(L, tLuaCOMEnumerator::garbagecollect);
  lua_setfield(L, -2, "__gc");

  lua_pop(L, 1);
  
  LUASTACK_CLEAN(L, 0);
}
Ejemplo n.º 6
0
void luaCompat_pushTypeByName(lua_State* L,
                               const char* module_name,
                               const char* type_name)
{ /* lua5 */
  LUASTACK_SET(L);

  luaCompat_moduleGet(L, module_name, type_name);

  if(lua_isnil(L, -1))
  {
    lua_pop(L, 1);
    luaCompat_newLuaType(L, module_name, type_name);
    luaCompat_moduleGet(L, module_name, type_name);    
  }

  LUASTACK_CLEAN(L, 1);
}