示例#1
0
void luaCompat_openlib(lua_State* L, const char* libname, const struct luaL_reg* funcs)
{ /* lua4 */
  LUASTACK_SET(L);

  char funcname[1000];

  lua_newtable(L);  /* create it */
  lua_pushvalue(L, -1);
  lua_setglobal(L, libname);  /* register it with given name */

  for (; funcs->name; funcs++)
  {
    int i;
    lua_pushstring(L, funcs->name);
    lua_pushcfunction(L, funcs->func);
    lua_settable(L, -3);

    funcname[0] = '\0';

    strncat(funcname, libname, 1000);
    strcat(funcname, "_");
    strncat(funcname, funcs->name, 1000 - strlen(libname) - strlen(funcs->name) - 2);
    lua_pushcfunction(L, funcs->func);
    lua_setglobal(L, funcname);
  }

  LUASTACK_CLEAN(L, 1);
}
示例#2
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;
}
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);
}
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);
}
示例#5
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);
}
示例#6
0
bool tLuaObject::pushCachedObject(lua_State *L, void *pointer)
{
  LUASTACK_SET(L);

#ifdef LUA5
  luaCompat_moduleGet(L, MODULENAME, INSTANCES_CACHE);

  lua_pushlightuserdata(L, pointer);
  lua_gettable(L, -2);

  lua_remove(L, -2);

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

    LUASTACK_CLEAN(L, 0);
    return false;
  }

  LUASTACK_CLEAN(L, 1);

  return true;
#else
  return false;
#endif
}
示例#7
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);
}
示例#8
0
int luaCompat_newTypedObject(lua_State* L, void* object)
{  /* lua4 */
  int newreference = 0;
  int tag = 0;

  LUASTACK_SET(L);

  luaL_checktype(L, -1, LUA_TNUMBER);

  tag = (int) lua_tonumber(L, -1);

  lua_pop(L, 1);

  /* pushes userdata */
  lua_pushusertag(L, object, LUA_ANYTAG);

  if(lua_tag(L, -1) != tag)
  {
    /* this is the first userdata with this value,
       so corrects the tag */
    lua_settag(L, tag);
    newreference = 1;
  }

  LUASTACK_CLEAN(L, 0);

  return newreference;
}
示例#9
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);
}
示例#10
0
void luaCompat_pushCBool(lua_State* L, int value)
{ /* lua5 */
  LUASTACK_SET(L);

  lua_pushboolean(L, value);

  LUASTACK_CLEAN(L, 1);
}
示例#11
0
LUAWINAPI_API int luaopen_luawinapi_core(lua_State *L)
{
  LUASTACK_SET(L);

  // init stdcallthunk module
  stdcallthunk_initialize();
  atexit(stdcallthunk_finalize);

  // luacwrap = require("luacwrap")
  lua_getglobal(L, "require");
  lua_pushstring(L, "luacwrap");
  lua_call(L, 1, 1);
  // lua_setfield(L, LUA_ENVIRONINDEX, "luacwrap");

  // get c interface
  lua_getfield(L, -1, LUACWARP_CINTERFACE_NAME);
  g_luacwrapiface = (luacwrap_cinterface*)lua_touserdata(L, -1);
  
  // check for C interface
  if (NULL == g_luacwrapiface)
  {
    luaL_error(L, "Could not load luacwrap: No C interface available.");
  }

  // check interface version
  if (LUACWARP_CINTERFACE_VERSION != g_luacwrapiface->version)
  {
    luaL_error(L, "Could not load luacwrap: Incompatiple C interface version. Expected %i got %i.", LUACWARP_CINTERFACE_VERSION, g_luacwrapiface->version);
  }
  
  // drop C interface and drop package table
  lua_pop(L, 2);

  // create module table
  lua_newtable(L);

  // set info fields
  lua_pushstring(L, "Klaus Oberhofer");
  lua_setfield(L, -2, "_AUTHOR");

  lua_pushstring(L, "1.3.0-1");
  lua_setfield(L, -2, "_VERSION");

  lua_pushstring(L, "MIT license: See LICENSE for details.");
  lua_setfield(L, -2, "_LICENSE");

  lua_pushstring(L, "https://github.com/oberhofer/luawinapi");
  lua_setfield(L, -2, "_URL");
  
  // register package functionality
  register_luawinapi(L);

  register_EnumChildWindows(L);

  LUASTACK_CLEAN(L, 1);
  return 1;
}
示例#12
0
void luaCompat_handleEqEvent(lua_State* L)
{ /* lua4 */
  LUASTACK_SET(L);

  /* lua4 does not have eq event */
  lua_pop(L, 1);

  LUASTACK_CLEAN(L, -1);
}
示例#13
0
void luaCompat_getType(lua_State* L, int index)
{ /* lua4 */
  LUASTACK_SET(L);

  int tag = lua_tag(L, index);
  lua_pushnumber(L, tag);

  LUASTACK_CLEAN(L, 1);
}
示例#14
0
void luaCompat_setType(lua_State* L, int index)
{ /* lua5 */

  LUASTACK_SET(L);

  lua_setmetatable(L, index);    

  LUASTACK_CLEAN(L,-1);
}
示例#15
0
void luaCompat_handleFuncCallEvent(lua_State* L)
{ /* lua4 */
  LUASTACK_SET(L);

  int tag = lua_tonumber(L, -2);

  lua_settagmethod(L, tag, "function");

  LUASTACK_CLEAN(L, -1);
}
示例#16
0
void luaCompat_handleNoIndexEvent(lua_State* L)
{ /* lua4 */
  LUASTACK_SET(L);

  int tag = lua_tonumber(L, -2);

  lua_settagmethod(L, tag, "index");

  LUASTACK_CLEAN(L, -1);
}
示例#17
0
void luaCompat_moduleGet(lua_State* L, const char* module, const char* key)
{
  LUASTACK_SET(L);

  lua_getfield(L, LUA_REGISTRYINDEX, module);
  lua_getfield(L, -1, key);
  lua_remove(L, -2);

  LUASTACK_CLEAN(L, 1);
}
示例#18
0
void luaCompat_getType(lua_State* L, int index)
{ /* lua5 */
  LUASTACK_SET(L);
  int result = lua_getmetatable(L, index);

  if(!result)
    lua_pushnil(L);

  LUASTACK_CLEAN(L, 1);
}
示例#19
0
void luaCompat_pushCBool(lua_State* L, int value)
{ /* lua4 */
  LUASTACK_SET(L);

  if(value)
    lua_pushnumber(L, 1);
  else
    lua_pushnumber(L, 0);

  LUASTACK_CLEAN(L, 1);
}
示例#20
0
void luaCompat_moduleSet(lua_State* L, const char* module, const char* key)
{
  LUASTACK_SET(L);

  lua_getfield(L, LUA_REGISTRYINDEX, module);
  lua_pushvalue(L, -2);
  lua_setfield(L, -2, key);
  lua_pop(L, 2);

  LUASTACK_CLEAN(L, -1);
}
示例#21
0
void luaCompat_handleFuncCallEvent(lua_State* L)
{ /* lua5 */
  LUASTACK_SET(L);

  lua_pushstring(L, "__call");
  lua_insert(L, -2);

  lua_settable(L, -3);

  LUASTACK_CLEAN(L, -1);
}
示例#22
0
void luaCompat_handleSettableEvent(lua_State* L)
{ /* lua5 */
  LUASTACK_SET(L);

  lua_pushstring(L, "__newindex");
  lua_insert(L, -2);

  lua_settable(L, -3);

  LUASTACK_CLEAN(L, -1);

}
示例#23
0
void luaCompat_openlib(lua_State* L, const char* libname, luaL_reg* funcs)
{ /* lua5 */
  LUASTACK_SET(L);

//#ifdef COMPAT-5.1
//  luaL_module(L, libname, funcs, 0);
//#else
  luaL_openlib(L, libname, funcs, 0);
//#endif

  LUASTACK_CLEAN(L, 1);
}
示例#24
0
void luaCompat_moduleGet(lua_State* L, const char* module, const char* key)
{ /* lua4 */
  LUASTACK_SET(L);

  lua_getglobal(L, module);
  lua_pushstring(L, key);

  lua_gettable(L, -2);

  lua_remove(L, -2);

  LUASTACK_CLEAN(L, 1);
}
int tLuaCOMEnumerator::garbagecollect(lua_State *L)
{
  LUASTACK_SET(L);

  // gets the enumerator
  tLuaCOMEnumerator* enumerator = 
    (tLuaCOMEnumerator*) luaCompat_getTypedObject(L, -1);

  delete enumerator;

  LUASTACK_CLEAN(L, 0);

  return 0;
}
示例#26
0
int tLuaCOMEnumerator::garbagecollect(lua_State *L)
{
  LUASTACK_SET(L);

  // gets the enumerator
  tLuaCOMEnumerator* enumerator = 
    (tLuaCOMEnumerator*)*(void **)lua_touserdata(L, -1);

  delete enumerator;

  LUASTACK_CLEAN(L, 0);

  return 0;
}
示例#27
0
void tLuaObject::cacheObject(lua_State *L, void* pointer)
{
  LUASTACK_SET(L);

  luaCompat_moduleGet(L, MODULENAME, INSTANCES_CACHE);

  lua_pushlightuserdata(L, pointer);
  lua_pushvalue(L, -3);
  lua_settable(L, -3);

  lua_remove(L, -1);

  LUASTACK_CLEAN(L, 0);
}
示例#28
0
int register_EnumChildWindows(lua_State* L)
{
  LUASTACK_SET(L);

  // create method table
#if (LUA_VERSION_NUM > 501)
  luaL_setfuncs(L, methods, 0);
#else
  luaL_openlib(L, NULL, methods, 0);
#endif

  LUASTACK_CLEAN(L, 0);
  return 0;
}
示例#29
0
void luaCompat_newLuaType(lua_State* L,
                           const char* module_name,
                           const char* type_name)
{ /* lua4 */
  LUASTACK_SET(L);

  int tag = lua_newtag(L);

  lua_pushnumber(L, tag);

  luaCompat_moduleSet(L, module_name, type_name);

  LUASTACK_CLEAN(L, 0);
}
示例#30
0
void luaCompat_moduleSet(lua_State* L, const char* module, const char* key)
{ /* lua4 */
  LUASTACK_SET(L);

  lua_getglobal(L, module);

  lua_pushstring(L, key);
  lua_pushvalue(L, -3);
  lua_settable(L, -3);

  lua_pop(L, 2);

  LUASTACK_CLEAN(L, -1);
}