1 // SONIC ROBO BLAST 2 2 //----------------------------------------------------------------------------- 3 // Copyright (C) 2012-2016 by John "JTE" Muniz. 4 // Copyright (C) 2012-2020 by Sonic Team Junior. 5 // 6 // This program is free software distributed under the 7 // terms of the GNU General Public License, version 2. 8 // See the 'LICENSE' file for more details. 9 //----------------------------------------------------------------------------- 10 /// \file lua_script.h 11 /// \brief Lua scripting basics 12 13 #ifndef LUA_SCRIPT_H 14 #define LUA_SCRIPT_H 15 16 #include "m_fixed.h" 17 #include "doomtype.h" 18 #include "d_player.h" 19 #include "g_state.h" 20 #include "taglist.h" 21 22 #include "blua/lua.h" 23 #include "blua/lualib.h" 24 #include "blua/lauxlib.h" 25 26 #define lua_optboolean(L, i) (!lua_isnoneornil(L, i) && lua_toboolean(L, i)) 27 #define lua_opttrueboolean(L, i) (lua_isnoneornil(L, i) || lua_toboolean(L, i)) 28 29 // fixed_t casting 30 // TODO add some distinction between fixed numbers and integer numbers 31 // for at least the purpose of printing and maybe math. 32 #define luaL_checkfixed(L, i) luaL_checkinteger(L, i) 33 #define lua_pushfixed(L, f) lua_pushinteger(L, f) 34 35 // angle_t casting 36 // TODO deal with signedness 37 #define luaL_checkangle(L, i) ((angle_t)luaL_checkinteger(L, i)) 38 #define lua_pushangle(L, a) lua_pushinteger(L, a) 39 40 #ifdef _DEBUG 41 void LUA_ClearExtVars(void); 42 #endif 43 44 extern INT32 lua_lumploading; // is LUA_LoadLump being called? 45 46 int LUA_GetErrorMessage(lua_State *L); 47 int LUA_Call(lua_State *L, int nargs, int nresults, int errorhandlerindex); 48 void LUA_LoadLump(UINT16 wad, UINT16 lump, boolean noresults); 49 #ifdef LUA_ALLOW_BYTECODE 50 void LUA_DumpFile(const char *filename); 51 #endif 52 fixed_t LUA_EvalMath(const char *word); 53 void LUA_Step(void); 54 void LUA_Archive(void); 55 void LUA_UnArchive(void); 56 int LUA_PushGlobals(lua_State *L, const char *word); 57 int LUA_CheckGlobals(lua_State *L, const char *word); 58 void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c 59 void LUA_CVarChanged(void *cvar); // lua_consolelib.c 60 int Lua_optoption(lua_State *L, int narg, 61 const char *def, const char *const lst[]); 62 void LUAh_NetArchiveHook(lua_CFunction archFunc); 63 64 void LUA_PushTaggableObjectArray 65 ( lua_State *L, 66 const char *field, 67 lua_CFunction iterator, 68 lua_CFunction indexer, 69 lua_CFunction counter, 70 taggroup_t *garray[], 71 size_t * max_elements, 72 void * element_array, 73 size_t sizeof_element, 74 const char *meta); 75 76 void LUA_InsertTaggroupIterator 77 ( lua_State *L, 78 taggroup_t *garray[], 79 size_t * max_elements, 80 void * element_array, 81 size_t sizeof_element, 82 const char * meta); 83 84 typedef enum { 85 LPUSHED_NIL, 86 LPUSHED_NEW, 87 LPUSHED_EXISTING, 88 } lpushed_t; 89 90 void LUA_PushUserdata(lua_State *L, void *data, const char *meta); 91 lpushed_t LUA_RawPushUserdata(lua_State *L, void *data); 92 93 void LUA_InvalidateUserdata(void *data); 94 95 void LUA_InvalidateLevel(void); 96 void LUA_InvalidateMapthings(void); 97 void LUA_InvalidatePlayer(player_t *player); 98 99 // Console wrapper 100 void COM_Lua_f(void); 101 102 #define LUA_ErrInvalid(L, type) luaL_error(L, "accessed " type " doesn't exist anymore, please check 'valid' before using " type "."); 103 104 #define LUA_ErrSetDirectly(L, type, field) luaL_error(L, type " field " LUA_QL(field) " cannot be set directly.") 105 106 // Deprecation warnings 107 // Shows once upon use. Then doesn't show again. 108 #define LUA_Deprecated(L,this_func,use_instead)\ 109 {\ 110 static UINT8 seen = 0;\ 111 if (!seen) {\ 112 seen = 1;\ 113 CONS_Alert(CONS_WARNING,"\"%s\" is deprecated and will be removed.\nUse \"%s\" instead.\n", this_func, use_instead);\ 114 }\ 115 } 116 117 // Warnings about incorrect function usage. 118 // Shows once, then never again, like deprecation 119 #define LUA_UsageWarning(L, warningmsg)\ 120 {\ 121 static UINT8 seen = 0;\ 122 if (!seen) {\ 123 seen = 1;\ 124 CONS_Alert(CONS_WARNING,"%s\n", warningmsg);\ 125 }\ 126 } 127 128 // uncomment if you want seg_t/node_t in Lua 129 // #define HAVE_LUA_SEGS 130 131 #define ISINLEVEL \ 132 (gamestate == GS_LEVEL || titlemapinaction) 133 134 #define INLEVEL if (! ISINLEVEL)\ 135 return luaL_error(L, "This can only be used in a level!"); 136 137 #endif/*LUA_SCRIPT_H*/ 138