Change all voice arrays to be exposed as arrays in Lua
For the sake of consistency and future expansion! Also expose mobj->voice (read-only for now, hopefully), and fix missing NOSET for player->voice_id
This commit is contained in:
parent
58b4949c24
commit
891459b53b
5 changed files with 72 additions and 10 deletions
|
|
@ -251,7 +251,8 @@ static const struct {
|
|||
{META_MATRIX, "matrix_t"},
|
||||
{META_QUATERNION, "quaternion_t"},
|
||||
{META_VOICE, "kartvoice_t"},
|
||||
{META_VOICE_ARRAY, "kartvoice_t.array"},
|
||||
{META_VOICE_ARRAY, "kartvoice_t.array[]"},
|
||||
{META_VOICE_ARRAY1, "kartvoice_t.array[1]"},
|
||||
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -124,7 +124,9 @@ extern lua_State *gL;
|
|||
#define META_QUATERNION "QUATERNION_T"
|
||||
|
||||
#define META_VOICE "KARTVOICE_T*"
|
||||
#define META_VOICE_ARRAY "KARTVOICE_T*ARRAY"
|
||||
#define META_VOICE_ARRAY "KARTVOICE_T*[]"
|
||||
// TODO: kill this one
|
||||
#define META_VOICE_ARRAY1 "KARTVOICE_T*[1]"
|
||||
|
||||
boolean luaL_checkboolean(lua_State *L, int narg);
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ enum mobj_e {
|
|||
mobj_eflags,
|
||||
mobj_renderflags,
|
||||
mobj_skin,
|
||||
mobj_voice,
|
||||
mobj_color,
|
||||
mobj_bnext,
|
||||
mobj_bprev,
|
||||
|
|
@ -161,6 +162,7 @@ static const char *const mobj_opt[] = {
|
|||
"eflags",
|
||||
"renderflags",
|
||||
"skin",
|
||||
"voice",
|
||||
"color",
|
||||
"bnext",
|
||||
"bprev",
|
||||
|
|
@ -427,6 +429,9 @@ static int mobj_get(lua_State *L)
|
|||
return 0;
|
||||
lua_pushstring(L, ((skin_t *)mo->skin)->name);
|
||||
break;
|
||||
case mobj_voice: // just push the struct damnit!
|
||||
LUA_PushUserdata(L, mo->voice, META_VOICE);
|
||||
break;
|
||||
case mobj_color:
|
||||
lua_pushinteger(L, mo->color);
|
||||
break;
|
||||
|
|
@ -901,6 +906,12 @@ static int mobj_set(lua_State *L)
|
|||
}
|
||||
return luaL_error(L, "mobj.skin '%s' not found!", skin);
|
||||
}
|
||||
case mobj_voice:
|
||||
// as much as i want to allow ironman without overwriting the player's skin,
|
||||
// letting the mobj's voice desync with the skin has some nasty implications at the moment
|
||||
return NOSET;
|
||||
//mo->voice = *((kartvoice_t **)luaL_checkudata(L, 3, META_VOICE));
|
||||
//break;
|
||||
case mobj_color:
|
||||
{
|
||||
UINT16 newcolor = (UINT16)luaL_checkinteger(L,3);
|
||||
|
|
|
|||
|
|
@ -1507,6 +1507,8 @@ static int player_set(lua_State *L)
|
|||
}
|
||||
case player_skin:
|
||||
return NOSET;
|
||||
case player_voice_id:
|
||||
return NOSET;
|
||||
case player_availabilities:
|
||||
return NOSET;
|
||||
case player_score:
|
||||
|
|
|
|||
|
|
@ -75,10 +75,10 @@ static int voice_get(lua_State* L)
|
|||
lua_pushstring(L, voice->name);
|
||||
break;
|
||||
case voicevars_win:
|
||||
LUA_PushUserdata(L, &S_sfx[voice->win], META_SFXINFO);
|
||||
LUA_PushUserdata(L, &voice->win, META_VOICE_ARRAY1);
|
||||
break;
|
||||
case voicevars_lose:
|
||||
LUA_PushUserdata(L, &S_sfx[voice->lose], META_SFXINFO);
|
||||
LUA_PushUserdata(L, &voice->lose, META_VOICE_ARRAY1);
|
||||
break;
|
||||
case voicevars_pain:
|
||||
LUA_PushUserdata(L, voice->pain, META_VOICE_ARRAY);
|
||||
|
|
@ -90,13 +90,13 @@ static int voice_get(lua_State* L)
|
|||
LUA_PushUserdata(L, voice->boost, META_VOICE_ARRAY);
|
||||
break;
|
||||
case voicevars_overtake:
|
||||
LUA_PushUserdata(L, &S_sfx[voice->overtake], META_SFXINFO);
|
||||
LUA_PushUserdata(L, &voice->overtake, META_VOICE_ARRAY1);
|
||||
break;
|
||||
case voicevars_hitem:
|
||||
LUA_PushUserdata(L, &S_sfx[voice->hitem], META_SFXINFO);
|
||||
LUA_PushUserdata(L, &voice->hitem, META_VOICE_ARRAY1);
|
||||
break;
|
||||
case voicevars_power:
|
||||
LUA_PushUserdata(L, &S_sfx[voice->power], META_SFXINFO);
|
||||
LUA_PushUserdata(L, &voice->power, META_VOICE_ARRAY1);
|
||||
break;
|
||||
default:
|
||||
return RNOFIELD;
|
||||
|
|
@ -181,9 +181,9 @@ static int voice_array_get(lua_State *L)
|
|||
INT32 i = luaL_checkinteger(L, 2);
|
||||
|
||||
if (i < 0 || i >= VOICEARRAYSIZE)
|
||||
return luaL_error(L, "index %d out of range (0 - %d)", i, VOICEARRAYSIZE);
|
||||
return luaL_error(L, "index %d out of range (0 - %d)", i, VOICEARRAYSIZE-1);
|
||||
|
||||
LUA_PushUserdata(L, &S_sfx[voice_array[i]], META_SFXINFO);
|
||||
lua_pushinteger(L, voice_array[i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +193,7 @@ static int voice_array_set(lua_State *L)
|
|||
INT32 i = luaL_checkinteger(L, 2);
|
||||
|
||||
if (i < 0 || i >= VOICEARRAYSIZE)
|
||||
return luaL_error(L, "index %d out of range (0 - %d)", i, VOICEARRAYSIZE);
|
||||
return luaL_error(L, "index %d out of range (0 - %d)", i, VOICEARRAYSIZE-1);
|
||||
|
||||
voice_array[i] = (sfxenum_t)luaL_checkinteger(L, 3);
|
||||
return 0;
|
||||
|
|
@ -206,6 +206,41 @@ static int voice_array_num(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// i would've liked to shove the length of the voice array into the userdata...
|
||||
// but this codebase is not ready for that, sooooo... have yet ANOTHER userdata type!
|
||||
|
||||
// voice_array, i -> voice.array[i]
|
||||
static int voice_array1_get(lua_State *L)
|
||||
{
|
||||
sfxenum_t *voice_array = *((sfxenum_t **)luaL_checkudata(L, 1, META_VOICE_ARRAY1));
|
||||
INT32 i = luaL_checkinteger(L, 2);
|
||||
|
||||
if (i < 0 || i >= 1)
|
||||
return luaL_error(L, "index %d out of range (0 - %d)", i, 1-1);
|
||||
|
||||
lua_pushinteger(L, voice_array[i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int voice_array1_set(lua_State *L)
|
||||
{
|
||||
sfxenum_t *voice_array = *((sfxenum_t **)luaL_checkudata(L, 1, META_VOICE_ARRAY1));
|
||||
INT32 i = luaL_checkinteger(L, 2);
|
||||
|
||||
if (i < 0 || i >= 1)
|
||||
return luaL_error(L, "index %d out of range (0 - %d)", i, 1-1);
|
||||
|
||||
voice_array[i] = (sfxenum_t)luaL_checkinteger(L, 3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// #voice.array -> 1
|
||||
static int voice_array1_num(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LUA_VoiceLib(lua_State* L)
|
||||
{
|
||||
luaL_newmetatable(L, META_VOICE);
|
||||
|
|
@ -230,5 +265,16 @@ int LUA_VoiceLib(lua_State* L)
|
|||
lua_setfield(L, -2, "__len");
|
||||
lua_pop(L,1);
|
||||
|
||||
luaL_newmetatable(L, META_VOICE_ARRAY1);
|
||||
lua_pushcfunction(L, voice_array1_get);
|
||||
lua_setfield(L, -2, "__index");
|
||||
|
||||
lua_pushcfunction(L, voice_array1_set);
|
||||
lua_setfield(L, -2, "__newindex");
|
||||
|
||||
lua_pushcfunction(L, voice_array1_num);
|
||||
lua_setfield(L, -2, "__len");
|
||||
lua_pop(L,1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue