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);
}
void tLuaCOMEnumerator::push(lua_State* L)
{
  LUASTACK_SET(L);

  // creates table
  lua_newtable(L);
  luaCompat_pushTypeByName(L, 
    tLuaCOMEnumerator::module_name, 
    tLuaCOMEnumerator::type_name);

  luaCompat_setType(L, -2);

  lua_pushstring(L, ENUMERATOR_FIELD);

  // pushes typed pointer
  luaCompat_pushTypeByName(L, 
    tLuaCOMEnumerator::module_name, 
    tLuaCOMEnumerator::pointer_type_name);

  luaCompat_newTypedObject(L, this);

  // stores in the table
  lua_settable(L, -3);

  LUASTACK_CLEAN(L, 1);
}
Exemple #3
0
int tLuaObject::generic_PushNew(lua_State* L,
                                tLuaObject* lua_obj,
                                const char* type_name,
                                const char* pointer_type_name
                                )
{
  LUASTACK_SET(L);

  // creates table
  lua_newtable(L);
  luaCompat_pushTypeByName(L, MODULENAME, type_name);

  lua_setmetatable(L, -2);

  lua_pushstring(L, TLUAOBJECT_POINTER_FIELD);

  // pushes typed pointer
  luaCompat_pushTypeByName(L, MODULENAME, pointer_type_name);

  luaCompat_newTypedObject(L, lua_obj);

  // stores in the table
  lua_settable(L, -3);

  LUASTACK_CLEAN(L, 1);

  return 1;
}
Exemple #4
0
void tLuaCOMEnumerator::push(lua_State* L)
{
  LUASTACK_SET(L);

  tStringBuffer module_name(tUtil::RegistryGetString(L, module_name_key));
  LUASTACK_DOCLEAN(L, 0);

  // creates table
  lua_newtable(L);
  luaCompat_pushTypeByName(L, 
    module_name, 
    tLuaCOMEnumerator::type_name);

  lua_setmetatable(L, -2);

  lua_pushstring(L, ENUMERATOR_FIELD);

  // pushes typed pointer
  luaCompat_pushTypeByName(L, 
    module_name, 
    tLuaCOMEnumerator::pointer_type_name);

  luaCompat_newTypedObject(L, this);

  // stores in the table
  lua_settable(L, -3);

  LUASTACK_CLEAN(L, 1);
}
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);
}
Exemple #6
0
void LuaBeans::registerPointerEvents(lua_State* L, class Events& events)
{
  LUASTACK_SET(L);

  luaCompat_pushTypeByName(L, module_name, udtag_name);

  if(events.gettable)
  {
    lua_pushcfunction(L, events.gettable);
    luaCompat_handleGettableEvent(L);
  }

  if(events.settable)
  {
    lua_pushcfunction(L, events.settable);
    luaCompat_handleSettableEvent(L);
  }

  if(events.noindex)
  {
    lua_pushcfunction(L, events.noindex);
    luaCompat_handleNoIndexEvent(L);
  }

  if(events.gc)
  {
    lua_pushcfunction(L, events.gc);
    luaCompat_handleGCEvent(L);
  }

  lua_pop(L, 1);

  LUASTACK_CLEAN(L, 0);
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  Method:   tLuaCOMConnPoint::tLuaCOMConnPoint

  Summary:  tLuaCOMConnPoint Constructor.

  Args:     IUnknown* pHostObj
              Pointer to IUnknown of the connectable object offering this
              connection point.

  Modifies: ...

  Returns:  void
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
tLuaCOMConnPoint::tLuaCOMConnPoint(lua_State *p_L,
                                   IUnknown* pHostObj)
{
  // stores lua state
  L = p_L;

  // Zero the COM object's reference count.
  cRefs = 0;

  // Remember an IUnknown pointer to the connectable object that offers
  // this connection point. Since this connection point object's lifetime
  // is geared to that of the connectable object there is no need to
  // AddRef the following copied pointer to the connectable object.
  pHostObj = pHostObj;

  // Initialize the Connection Point variables.
  dwNextCookie = COOKIE_START_VALUE;
  uiMaxIndex = 0;
  cConnections = 0;

  // creates a new lua tag associated with this connection point
  luaCompat_pushTypeByName(L, MODULENAME, LCOM_CONNPOINT_TYPENAME);
  lua_pushcfunction(L, tagmeth_index);
  luaCompat_handleNoIndexEvent(L);

  lua_pop(L, 1);

  for(int i = 0; i < ALLOC_CONNECTIONS; i++)
    sinks[i] = NULL;


  return;
}
Exemple #8
0
void LuaBeans::push(lua_State* L, void* userdata )
{
  LUASTACK_SET(L);

  lua_newtable(L);

  lua_pushstring(L, "_USERDATA_REF_");

  luaCompat_pushTypeByName(L, module_name, udtag_name);
  luaCompat_newTypedObject(L, userdata);

  lua_settable(L, -3);

  luaCompat_pushTypeByName(L, module_name, tag_name);
  luaCompat_setType(L, -2);

  LUASTACK_CLEAN(L, 1);
}
Exemple #9
0
void LuaBeans::push( void* userdata )
{
  LUASTACK_SET(L);

  lua_newtable(L);

  lua_pushstring(L, "_USERDATA_REF_");

  luaCompat_pushTypeByName(L, module_name, udtag_name);
  luaCompat_newTypedObject(L, userdata);

  lua_settable(L, -3);

  if (this->mlist)
    register_methods(L, -1, this->mlist->table, this->mlist->n);

  luaCompat_pushTypeByName(L, module_name, tag_name);
  luaCompat_setType(L, -2);

  LUASTACK_CLEAN(L, 1);
}
Exemple #10
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);
}
void tLuaCOMConnPoint::push()
{
  LUASTACK_SET(L);

  lua_newtable(L);
  luaCompat_pushTypeByName(L, MODULENAME, LCOM_CONNPOINT_TYPENAME);
  luaCompat_setType(L, -2);

  lua_pushstring(L, CONNPOINT_NAME);
  luaCompat_pushPointer(L, this);

  lua_settable(L, -3);

  LUASTACK_CLEAN(L, 1);
}
Exemple #12
0
int luaCompat_isOfType(lua_State* L, const char* module, const char* type)
{ /* lua5 */
  int result = 0;
  LUASTACK_SET(L);

  luaCompat_getType(L, -1);
  luaCompat_pushTypeByName(L, module, type);

  result = (lua_equal(L, -1, -2) ? 1 : 0);

  lua_pop(L, 2);

  LUASTACK_CLEAN(L, 0);

  return result;
}
Exemple #13
0
int luaCompat_isOfType(lua_State* L, const char* module, const char* type)
{
  int result = 0;
  LUASTACK_SET(L);

  luaCompat_getType(L, -1);
  luaCompat_pushTypeByName(L, module, type);

#if LUA_VERSION_NUM <= 501
  result = (lua_equal(L, -1, -2) ? 1 : 0);
#else
  result = (lua_compare(L, -1, -2, LUA_OPEQ) ? 1 : 0);
#endif

  lua_pop(L, 2);

  LUASTACK_CLEAN(L, 0);

  return result;
}
Exemple #14
0
void LuaBeans::registerObjectEvents(class Events& events)
{
  LUASTACK_SET(L);

  luaCompat_pushTypeByName(L, module_name, tag_name);

  if(events.gettable)
  {
    lua_pushcfunction(L, events.gettable);
    luaCompat_handleGettableEvent(L);
  }

  if(events.settable)
  {
    lua_pushcfunction(L, events.settable);
    luaCompat_handleSettableEvent(L);
  }

  if(events.noindex)
  {
    lua_pushcfunction(L, events.noindex);
    luaCompat_handleNoIndexEvent(L);
  }

  if(events.call)
  {
    lua_pushcfunction(L, events.call);
    luaCompat_handleFuncCallEvent(L);
  }

  if(events.gc)
  {
    lua_pushcfunction(L, events.gc);
    luaCompat_handleGCEvent(L);
  }

  lua_pop(L, 1);

  LUASTACK_CLEAN(L, 0);
}
Exemple #15
0
LuaBeans* LuaBeans::createBeans(lua_State *L,
                                const char* module_name,
                                const char* name)
{
  LUASTACK_SET(L);

  luaCompat_moduleGet(L, module_name, "LuaBeansTable");

  if(lua_isnil(L, -1))
  {
    lua_pop(L, 1);

    lua_newtable(L);

    lua_pushvalue(L, -1);

    luaCompat_moduleSet(L, module_name, "LuaBeansTable");
  }
 
  lua_pushstring(L, (char*)name);

  LuaBeans* lbeans = new LuaBeans(L, module_name, name);
  luaCompat_pushTypeByName(L, module_name, "LuaBeansObject");

  // sets GC callback
  lua_pushcfunction(L, LuaBeans::gc);
  luaCompat_handleGCEvent(L);

  luaCompat_newTypedObject(L, lbeans);

  lua_settable(L, -3);

  lua_pop(L, 1);

  LUASTACK_CLEAN(L, 0);

  return lbeans;
}