simplify LUA_Alloc
Z_Realloc already handles everything internally, no need to manually free anything
This commit is contained in:
parent
526a8390f5
commit
5cc8998974
2 changed files with 30 additions and 33 deletions
|
|
@ -33,7 +33,7 @@ extern CV_PossibleValue_t Color_cons_t[];
|
||||||
extern UINT8 skincolor_modified[];
|
extern UINT8 skincolor_modified[];
|
||||||
|
|
||||||
boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor);
|
boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor);
|
||||||
state_t *astate;
|
state_t *astate = NULL;
|
||||||
|
|
||||||
enum sfxinfo_read {
|
enum sfxinfo_read {
|
||||||
sfxinfor_name = 0,
|
sfxinfor_name = 0,
|
||||||
|
|
|
||||||
|
|
@ -45,31 +45,31 @@ boolean lua_compatmode = false;
|
||||||
|
|
||||||
// List of internal libraries to load from SRB2
|
// List of internal libraries to load from SRB2
|
||||||
static lua_CFunction liblist[] = {
|
static lua_CFunction liblist[] = {
|
||||||
LUA_EnumLib, // global metatable for enums
|
LUA_EnumLib, // global metatable for enums
|
||||||
LUA_SOCLib, // A_Action functions, freeslot
|
LUA_SOCLib, // A_Action functions, freeslot
|
||||||
LUA_BaseLib, // string concatination by +, CONS_Printf, p_local.h stuff (P_InstaThrust, P_Move), etc.
|
LUA_BaseLib, // string concatination by +, CONS_Printf, p_local.h stuff (P_InstaThrust, P_Move), etc.
|
||||||
LUA_MathLib, // fixed_t and angle_t math functions
|
LUA_MathLib, // fixed_t and angle_t math functions
|
||||||
LUA_HookLib, // hookAdd and hook-calling functions
|
LUA_HookLib, // hookAdd and hook-calling functions
|
||||||
LUA_ConsoleLib, // console command/variable functions and structs
|
LUA_ConsoleLib, // console command/variable functions and structs
|
||||||
LUA_InfoLib, // info.h stuff: mobjinfo_t, mobjinfo[], state_t, states[]
|
LUA_InfoLib, // info.h stuff: mobjinfo_t, mobjinfo[], state_t, states[]
|
||||||
LUA_MobjLib, // mobj_t, mapthing_t
|
LUA_MobjLib, // mobj_t, mapthing_t
|
||||||
LUA_PlayerLib, // player_t
|
LUA_PlayerLib, // player_t
|
||||||
LUA_SkinLib, // skin_t, skins[]
|
LUA_SkinLib, // skin_t, skins[]
|
||||||
LUA_ThinkerLib, // thinker_t
|
LUA_ThinkerLib, // thinker_t
|
||||||
LUA_MapLib, // line_t, side_t, sector_t, subsector_t
|
LUA_MapLib, // line_t, side_t, sector_t, subsector_t
|
||||||
LUA_TagLib, // tags
|
LUA_TagLib, // tags
|
||||||
LUA_PolyObjLib, // polyobj_t
|
LUA_PolyObjLib, // polyobj_t
|
||||||
LUA_BlockmapLib, // blockmap stuff
|
LUA_BlockmapLib, // blockmap stuff
|
||||||
LUA_HudLib, // HUD stuff
|
LUA_HudLib, // HUD stuff
|
||||||
LUA_FollowerLib, // follower_t, followers[]
|
LUA_FollowerLib, // follower_t, followers[]
|
||||||
LUA_BotVarsLib, // botvars_t
|
LUA_BotVarsLib, // botvars_t
|
||||||
LUA_TerrainLib, // t_splash_t, t_footstep_t, t_overlay_t, terrain_t
|
LUA_TerrainLib, // t_splash_t, t_footstep_t, t_overlay_t, terrain_t
|
||||||
LUA_WaypointLib, // waypoint_t
|
LUA_WaypointLib, // waypoint_t
|
||||||
LUA_VectorLib, // vectors
|
LUA_VectorLib, // vectors
|
||||||
LUA_MatrixLib, // matrices
|
LUA_MatrixLib, // matrices
|
||||||
LUA_QuaternionLib, // quaternions
|
LUA_QuaternionLib, // quaternions
|
||||||
LUA_VoiceLib, // kartvoice_t, skinvoices[]
|
LUA_VoiceLib, // kartvoice_t, skinvoices[]
|
||||||
LUA_ItemLib, // kartitem_t, kartresult_t, kartitemgraphics_t
|
LUA_ItemLib, // kartitem_t, kartresult_t, kartitemgraphics_t
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -77,12 +77,8 @@ static lua_CFunction liblist[] = {
|
||||||
static void *LUA_Alloc(void *ud, void *ptr, size_t osize, size_t nsize)
|
static void *LUA_Alloc(void *ud, void *ptr, size_t osize, size_t nsize)
|
||||||
{
|
{
|
||||||
(void)ud;
|
(void)ud;
|
||||||
if (nsize == 0) {
|
(void)osize;
|
||||||
if (osize != 0)
|
return Z_Realloc(ptr, nsize, PU_LUA, NULL);
|
||||||
Z_Free(ptr);
|
|
||||||
return NULL;
|
|
||||||
} else
|
|
||||||
return Z_Realloc(ptr, nsize, PU_LUA, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panic function Lua calls when there's an unprotected error.
|
// Panic function Lua calls when there's an unprotected error.
|
||||||
|
|
@ -690,7 +686,8 @@ void LUA_ClearState(void)
|
||||||
lua_setfield(L, LUA_REGISTRYINDEX, LREG_METATABLES);
|
lua_setfield(L, LUA_REGISTRYINDEX, LREG_METATABLES);
|
||||||
|
|
||||||
// open srb2 libraries
|
// open srb2 libraries
|
||||||
for(i = 0; liblist[i]; i++) {
|
for (i = 0; liblist[i]; i++)
|
||||||
|
{
|
||||||
lua_pushcfunction(L, liblist[i]);
|
lua_pushcfunction(L, liblist[i]);
|
||||||
lua_call(L, 0, 0);
|
lua_call(L, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue