Expose S_FindMusicCredit and musiccredit_t to lua
This commit is contained in:
1 parent
f15d3be263
commit
279dfcafc4
2 files changed
+81
-1
No files matched your search
@@ -16,6 +16,7 @@
|
||||
#include "dehacked.h"
|
||||
#include "p_mobj.h"
|
||||
#include "p_local.h"
|
||||
#include "s_sound.h"
|
||||
#include "z_zone.h"
|
||||
|
||||
#include "lua_script.h"
|
||||
@@ -1072,6 +1073,72 @@ static int sfxinfo_num(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
enum musicdef_e {
|
||||
musicdef_name = 0,
|
||||
musicdef_usage,
|
||||
musicdef_source,
|
||||
musicdef_filename,
|
||||
musicdef_title,
|
||||
musicdef_alttitle,
|
||||
musicdef_authors,
|
||||
};
|
||||
|
||||
const char *const musicdef_opt[] = {
|
||||
"name",
|
||||
"usage",
|
||||
"source",
|
||||
"filename",
|
||||
"title",
|
||||
"alttitle",
|
||||
"authors",
|
||||
NULL
|
||||
};
|
||||
|
||||
static int musicdef_fields_ref = LUA_NOREF;
|
||||
|
||||
static int lib_sFindMusicCredit(lua_State *L)
|
||||
{
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
LUA_PushUserdata(L, S_FindMusicCredit(name), META_MUSICDEF);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int musicdef_get(lua_State *L)
|
||||
{
|
||||
musicdef_t *musicdef = *((musicdef_t **)luaL_checkudata(L, 1, META_MUSICDEF));
|
||||
enum musicdef_e field = Lua_optoption(L, 2, -1, musicdef_fields_ref);
|
||||
|
||||
I_Assert(musicdef != NULL);
|
||||
|
||||
switch (field)
|
||||
{
|
||||
case musicdef_name:
|
||||
lua_pushstring(L, musicdef->name);
|
||||
return 1;
|
||||
case musicdef_usage:
|
||||
lua_pushstring(L, musicdef->usage);
|
||||
return 1;
|
||||
case musicdef_source:
|
||||
lua_pushstring(L, musicdef->source);
|
||||
return 1;
|
||||
case musicdef_filename:
|
||||
lua_pushstring(L, musicdef->filename);
|
||||
return 1;
|
||||
case musicdef_title:
|
||||
lua_pushstring(L, musicdef->title);
|
||||
return 1;
|
||||
case musicdef_alttitle:
|
||||
lua_pushstring(L, musicdef->alttitle);
|
||||
return 1;
|
||||
case musicdef_authors:
|
||||
lua_pushstring(L, musicdef->authors);
|
||||
return 1;
|
||||
default:
|
||||
return luaL_error(L, LUA_QL("musicdef_t") " has no field named " LUA_QS, lua_tostring(L, 2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//
|
||||
// Now push all these functions into the Lua state!
|
||||
@@ -1126,6 +1193,15 @@ int LUA_InfoLib(lua_State *L)
|
||||
|
||||
sfxinfo_fields_ref = Lua_CreateFieldTable(L, sfxinfo_opt);
|
||||
|
||||
luaL_newmetatable(L, META_MUSICDEF);
|
||||
lua_pushcfunction(L, musicdef_get);
|
||||
lua_setfield(L, -2, "__index");
|
||||
lua_pop(L, 1);
|
||||
|
||||
musicdef_fields_ref = Lua_CreateFieldTable(L, musicdef_opt);
|
||||
|
||||
lua_register(L, "S_FindMusicCredit", lib_sFindMusicCredit);
|
||||
|
||||
lua_newuserdata(L, 0);
|
||||
lua_createtable(L, 0, 2);
|
||||
lua_pushcfunction(L, lib_getSprname);
|
||||
|
||||
+5
-1
@@ -10,6 +10,9 @@
|
||||
/// \file lua_libs.h
|
||||
/// \brief libraries for Lua scripting
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "blua/lua.h"
|
||||
|
||||
extern lua_State *gL;
|
||||
|
||||
#define LREG_VALID "VALID_USERDATA"
|
||||
@@ -20,6 +23,7 @@ extern lua_State *gL;
|
||||
#define META_STATE "STATE_T*"
|
||||
#define META_MOBJINFO "MOBJINFO_T*"
|
||||
#define META_SFXINFO "SFXINFO_T*"
|
||||
#define META_MUSICDEF "MUSICDEF_T*"
|
||||
|
||||
#define META_MOBJ "MOBJ_T*"
|
||||
#define META_MAPTHING "MAPTHING_T*"
|
||||
@@ -68,4 +72,4 @@ int LUA_SkinLib(lua_State *L);
|
||||
int LUA_ThinkerLib(lua_State *L);
|
||||
int LUA_MapLib(lua_State *L);
|
||||
int LUA_BlockmapLib(lua_State *L);
|
||||
int LUA_HudLib(lua_State *L);
|
||||
int LUA_HudLib(lua_State *L);
|
||||
Reference in new issue
Block a user