Ejemplo n.º 1
0
/* Release ownership
*/
static int tolua_bnd_releaseownership (lua_State* L)
{
	int done = 0;
	if (lua_isuserdata(L,1))
	{
		void* u = *((void**)lua_touserdata(L,1));
		/* force garbage collection to avoid releasing a to-be-collected address */
		#ifdef LUA_VERSION_NUM
		lua_gc(L, LUA_GCCOLLECT, 0);
		#else
		lua_setgcthreshold(L,0);
		#endif
		lua_pushstring(L,"tolua_gc");
		lua_rawget(L,LUA_REGISTRYINDEX);
		lua_pushlightuserdata(L,u);
		lua_rawget(L,-2);
		lua_getmetatable(L,1);
		if (lua_rawequal(L,-1,-2))  /* check that we are releasing the correct type */
		{
			lua_pushlightuserdata(L,u);
			lua_pushnil(L);
			lua_rawset(L,-5);
			done = 1;
		}
	}
	lua_pushboolean(L,done!=0);
	return 1;
}
Ejemplo n.º 2
0
void tolua_takeownership (lua_State* L, int lo)
{
 if (toluaI_tt_isusertype(L,lo))
 {
  /* force garbage collection to avoid C to reuse a to-be-collected address */
  lua_setgcthreshold(L,0);
  tolua_doclone(L,lua_touserdata(L,lo),lua_tag(L,lo));  
 }
 else
  tolua_error(L,"cannot take ownership of specified obejct.");
}
Ejemplo n.º 3
0
/* Take ownership
*/
static int tolua_bnd_takeownership (lua_State* L)
{
    int success = 0;
    if (lua_isuserdata(L,1))
    {
        if (lua_getmetatable(L,1))        /* if metatable? */
        {
            lua_pop(L,1);             /* clear metatable off stack */
            /* force garbage collection to avoid C to reuse a to-be-collected address */
            lua_setgcthreshold(L,0);
            success = tolua_register_gc(L,1);
        }
    }
    lua_pushboolean(L,success!=0);
    return 1;
}
Ejemplo n.º 4
0
/* Take ownership
*/
static int tolua_bnd_takeownership (lua_State* L)
{
	lua_CFunction func = 0;
	if (lua_isuserdata(L,1))
	{
		if (lua_getmetatable(L,1))        /* if metatable? */
		{
			void* u;
			lua_pushstring(L,".collector");
   lua_rawget(L,-2);
			func = lua_tocfunction(L,-1);    /* it may be NULL; it is ok */
			lua_pop(L,2);
	  u = *((void**)lua_touserdata(L,1));
			/* force garbage collection to avoid C to reuse a to-be-collected address */
			lua_setgcthreshold(L,0);
			tolua_clone(L,u,func);
		}
	}
	lua_pushboolean(L,func!=0);
	return 1;
}
Ejemplo n.º 5
0
/* Release ownership
*/
static int tolua_bnd_releaseownership (lua_State* L)
{
	int done = 0;
	if (lua_isuserdata(L,1))
	{
	 void* u = *((void**)lua_touserdata(L,1));
		/* force garbage collection to avoid releasing a to-be-collected address */
		lua_setgcthreshold(L,0);
  lua_pushstring(L,"tolua_gc");
  lua_rawget(L,LUA_REGISTRYINDEX);
	 lua_pushlightuserdata(L,u);
	 lua_rawget(L,-2);
	 if (lua_isfunction(L,-1))
	 {
	  lua_pushlightuserdata(L,u);
		 lua_pushnil(L);
		 lua_rawset(L,-4);
   done = 1;
		}
	}
	lua_pushboolean(L,done!=0);
	return 1;
}
Ejemplo n.º 6
0
static int luaB_collectgarbage (lua_State *L) {
  lua_setgcthreshold(L, luaL_optint(L, 1, 0));
  return 0;
}
Ejemplo n.º 7
0
static void unpersist(UnpersistInfo *upi) {
	/* perms reftbl ... */
	int firstTime;
	int stacksize = lua_gettop(upi->L); /* DEBUG */
	luaZ_read(&upi->zio, &firstTime, sizeof(int));
	if(firstTime) {
		int ref;
		int type;
		luaZ_read(&upi->zio, &ref, sizeof(int));
		lua_assert(!inreftable(upi->L, ref));
		luaZ_read(&upi->zio, &type, sizeof(int));
#ifdef PLUTO_DEBUG

		printindent(upi->level);
		printf("1 %d %d\n", ref, type);
		upi->level++;
#endif

		switch(type) {
		case LUA_TBOOLEAN:
			unpersistboolean(upi);
			break;
		case LUA_TLIGHTUSERDATA:
			unpersistlightuserdata(upi);
			break;
		case LUA_TNUMBER:
			unpersistnumber(upi);
			break;
		case LUA_TSTRING:
			unpersiststring(upi);
			break;
		case LUA_TTABLE:
			unpersisttable(ref, upi);
			break;
		case LUA_TFUNCTION:
			unpersistfunction(ref, upi);
			break;
		case LUA_TTHREAD:
			unpersistthread(ref, upi);
			break;
		case LUA_TPROTO:
			unpersistproto(ref, upi);
			break;
		case LUA_TUPVAL:
			unpersistupval(ref, upi);
			break;
		case LUA_TUSERDATA:
			unpersistuserdata(ref, upi);
			break;
		case PLUTO_TPERMANENT:
			unpersistpermanent(ref, upi);
			break;
		default:
			lua_assert(0);
		}
		/* perms reftbl ... obj */
		lua_assert(lua_type(upi->L, -1) == type ||
		           type == PLUTO_TPERMANENT ||
		           /* Remember, upvalues get a special dispensation, as
		            * described in boxupval */
		           (lua_type(upi->L, -1) == LUA_TFUNCTION &&
		            type == LUA_TUPVAL));
		registerobject(ref, upi);
		/* perms reftbl ... obj */
#ifdef PLUTO_DEBUG

		upi->level--;
#endif

	} else {
		int ref;
		luaZ_read(&upi->zio, &ref, sizeof(int));
#ifdef PLUTO_DEBUG

		printindent(upi->level);
		printf("0 %d\n", ref);
#endif

		if(ref == 0) {
			lua_pushnil(upi->L);
			/* perms reftbl ... nil */
		} else {
			lua_pushlightuserdata(upi->L, (void*)ref);
			/* perms reftbl ... ref */
			lua_gettable(upi->L, 2);
			/* perms reftbl ... obj? */
			lua_assert(!lua_isnil(upi->L, -1));
		}
		/* perms reftbl ... obj/nil */
	}
	/* perms reftbl ... obj/nil */
	lua_assert(lua_gettop(upi->L) == stacksize + 1);
	lua_setgcthreshold(upi->L, 0);
	lua_setgcthreshold(upi->L, 0);
}
Ejemplo n.º 8
0
/**
 * @version 05/06/08	Bang2ni - __get_guildid_byname 스크립트 함수 등록
 */
bool CQuestManager::InitializeLua()
{
#if LUA_V == 503
    L = lua_open();

    luaopen_base(L);
    luaopen_table(L);
    luaopen_string(L);
    luaopen_math(L);
    //TEMP
    luaopen_io(L);
    luaopen_debug(L);
#elif LUA_V == 523
    L = luaL_newstate();

    luaL_openlibs(L);
    //luaopen_debug(L);
#else
#error "lua version not found"
#endif

    RegisterAffectFunctionTable();
    RegisterBuildingFunctionTable();
    RegisterDungeonFunctionTable();
    RegisterGameFunctionTable();
    RegisterGuildFunctionTable();
    RegisterHorseFunctionTable();
#ifdef __PET_SYSTEM__
    RegisterPetFunctionTable();
#endif
    RegisterITEMFunctionTable();
    RegisterMarriageFunctionTable();
    RegisterNPCFunctionTable();
    RegisterPartyFunctionTable();
    RegisterPCFunctionTable();
    RegisterQuestFunctionTable();
    RegisterTargetFunctionTable();
    RegisterArenaFunctionTable();
    RegisterForkedFunctionTable();
    RegisterMonarchFunctionTable();
    RegisterOXEventFunctionTable();
    RegisterMgmtFunctionTable();
    RegisterBattleArenaFunctionTable();
    RegisterDanceEventFunctionTable();
    RegisterDragonLairFunctionTable();
    RegisterSpeedServerFunctionTable();
    RegisterDragonSoulFunctionTable();

    {
        luaL_reg member_functions[] =
        {
            { "chat",			member_chat		},
            { "set_ready",			member_set_ready	},
            { "clear_ready",		member_clear_ready	},
            { NULL,				NULL			}
        };

        AddLuaFunctionTable("member", member_functions);
    }

    {
        luaL_reg highscore_functions[] =
        {
            { "register",			highscore_register	},
            { "show",			highscore_show		},
            { NULL,				NULL			}
        };

        AddLuaFunctionTable("highscore", highscore_functions);
    }

    {
        luaL_reg mob_functions[] =
        {
            { "spawn",			mob_spawn		},
            { "spawn_group",		mob_spawn_group		},
            { NULL,				NULL			}
        };

        AddLuaFunctionTable("mob", mob_functions);
    }

    //
    // global namespace functions
    //
    RegisterGlobalFunctionTable(L);

    // LUA_INIT_ERROR_MESSAGE
    {
        char settingsFileName[256];
        snprintf(settingsFileName, sizeof(settingsFileName), "%s/settings.lua", LocaleService_GetBasePath().c_str());

        int settingsLoadingResult = lua_dofile(L, settingsFileName);
        sys_log(0, "LoadSettings(%s), returns %d", settingsFileName, settingsLoadingResult);
        if (settingsLoadingResult != 0)
        {
            sys_err("LOAD_SETTINS_FAILURE(%s)", settingsFileName);
            return false;
        }
    }

    {
        char questlibFileName[256];
        snprintf(questlibFileName, sizeof(questlibFileName), "%s/questlib.lua", LocaleService_GetQuestPath().c_str());

        int questlibLoadingResult = lua_dofile(L, questlibFileName);
        sys_log(0, "LoadQuestlib(%s), returns %d", questlibFileName, questlibLoadingResult);
        if (questlibLoadingResult != 0)
        {
            sys_err("LOAD_QUESTLIB_FAILURE(%s)", questlibFileName);
            return false;
        }
    }

    if (LC_IsEurope())
    {
        char translateFileName[256];
        snprintf(translateFileName, sizeof(translateFileName), "%s/translate.lua", LocaleService_GetBasePath().c_str());

        int translateLoadingResult = lua_dofile(L, translateFileName);
        sys_log(0, "LoadTranslate(%s), returns %d", translateFileName, translateLoadingResult);
        if (translateLoadingResult != 0)
        {
            sys_err("LOAD_TRANSLATE_ERROR(%s)", translateFileName);
            return false;
        }
    }

    {
        char questLocaleFileName[256];
        if (LC_IsEurope())
        {
            snprintf(questLocaleFileName, sizeof(questLocaleFileName), "%s/locale.lua", g_stQuestDir.c_str());
        }
        else
        {
            snprintf(questLocaleFileName, sizeof(questLocaleFileName), "%s/locale_%s.lua", g_stQuestDir.c_str(), g_stLocale.c_str());
        }

        int questLocaleLoadingResult = lua_dofile(L, questLocaleFileName);
        sys_log(0, "LoadQuestLocale(%s), returns %d", questLocaleFileName, questLocaleLoadingResult);
        if (questLocaleLoadingResult != 0)
        {
            sys_err("LoadQuestLocale(%s) FAILURE", questLocaleFileName);
            return false;
        }
    }
    // END_OF_LUA_INIT_ERROR_MESSAGE

    for (itertype(g_setQuestObjectDir) it = g_setQuestObjectDir.begin(); it != g_setQuestObjectDir.end(); ++it)
    {
        const string& stQuestObjectDir = *it;
        char buf[PATH_MAX];
        snprintf(buf, sizeof(buf), "%s/state/", stQuestObjectDir.c_str());
        DIR * pdir = opendir(buf);
        int iQuestIdx = 0;

        if (pdir)
        {
            dirent * pde;

            while ((pde = readdir(pdir)))
            {
                if (pde->d_name[0] == '.')
                    continue;

                snprintf(buf + 11, sizeof(buf) - 11, "%s", pde->d_name);

                RegisterQuest(pde->d_name, ++iQuestIdx);
                int ret = lua_dofile(L, (stQuestObjectDir + "/state/" + pde->d_name).c_str());
                sys_log(0, "QUEST: loading %s, returns %d", (stQuestObjectDir + "/state/" + pde->d_name).c_str(), ret);

                BuildStateIndexToName(pde->d_name);
            }

            closedir(pdir);
        }
    }

#if LUA_V == 503
    lua_setgcthreshold(L, 0);
#endif
    lua_newtable(L);
    lua_setglobal(L, "__codecache");
    return true;
}
Ejemplo n.º 9
0
void scripting_RunGC() {
  lua_setgcthreshold(L, 0);
}