2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-05-18 00:42:11 +00:00
|
|
|
// Copyright (C) 2012-2016 by John "JTE" Muniz.
|
2023-03-31 12:53:31 +00:00
|
|
|
// Copyright (C) 2012-2023 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file lua_script.h
|
|
|
|
/// \brief Lua scripting basics
|
|
|
|
|
2020-12-04 08:30:08 +00:00
|
|
|
#ifndef LUA_SCRIPT_H
|
|
|
|
#define LUA_SCRIPT_H
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
#include "m_fixed.h"
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "d_player.h"
|
2019-07-30 16:57:57 +00:00
|
|
|
#include "g_state.h"
|
2020-12-04 08:30:08 +00:00
|
|
|
#include "taglist.h"
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
#include "blua/lua.h"
|
|
|
|
#include "blua/lualib.h"
|
|
|
|
#include "blua/lauxlib.h"
|
2015-05-21 03:54:04 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
#define lua_optboolean(L, i) (!lua_isnoneornil(L, i) && lua_toboolean(L, i))
|
|
|
|
#define lua_opttrueboolean(L, i) (lua_isnoneornil(L, i) || lua_toboolean(L, i))
|
|
|
|
|
2015-05-21 03:54:04 +00:00
|
|
|
// fixed_t casting
|
|
|
|
// TODO add some distinction between fixed numbers and integer numbers
|
|
|
|
// for at least the purpose of printing and maybe math.
|
|
|
|
#define luaL_checkfixed(L, i) luaL_checkinteger(L, i)
|
|
|
|
#define lua_pushfixed(L, f) lua_pushinteger(L, f)
|
|
|
|
|
|
|
|
// angle_t casting
|
2015-05-21 03:54:04 +00:00
|
|
|
// TODO deal with signedness
|
|
|
|
#define luaL_checkangle(L, i) ((angle_t)luaL_checkinteger(L, i))
|
|
|
|
#define lua_pushangle(L, a) lua_pushinteger(L, a)
|
2015-05-21 03:54:04 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
void LUA_ClearExtVars(void);
|
|
|
|
#endif
|
|
|
|
|
2020-05-29 15:35:07 +00:00
|
|
|
extern INT32 lua_lumploading; // is LUA_LoadLump being called?
|
2017-04-25 20:45:53 +00:00
|
|
|
|
2020-05-30 18:24:33 +00:00
|
|
|
int LUA_GetErrorMessage(lua_State *L);
|
2020-11-13 17:35:22 +00:00
|
|
|
int LUA_Call(lua_State *L, int nargs, int nresults, int errorhandlerindex);
|
2021-09-05 19:38:51 +00:00
|
|
|
boolean LUA_LoadLump(UINT16 wad, UINT16 lump);
|
|
|
|
void LUA_DoLump(UINT16 wad, UINT16 lump, boolean noresults);
|
2014-03-15 16:59:03 +00:00
|
|
|
#ifdef LUA_ALLOW_BYTECODE
|
|
|
|
void LUA_DumpFile(const char *filename);
|
|
|
|
#endif
|
|
|
|
fixed_t LUA_EvalMath(const char *word);
|
2015-06-10 17:42:45 +00:00
|
|
|
void LUA_Step(void);
|
2014-03-15 16:59:03 +00:00
|
|
|
void LUA_Archive(void);
|
|
|
|
void LUA_UnArchive(void);
|
2019-12-23 21:49:23 +00:00
|
|
|
int LUA_PushGlobals(lua_State *L, const char *word);
|
|
|
|
int LUA_CheckGlobals(lua_State *L, const char *word);
|
2014-03-15 16:59:03 +00:00
|
|
|
void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c
|
2021-05-03 04:59:23 +00:00
|
|
|
void LUA_CVarChanged(void *cvar); // lua_consolelib.c
|
2023-06-18 16:05:16 +00:00
|
|
|
int Lua_optoption(lua_State *L, int narg, int def, int list_ref);
|
|
|
|
int Lua_CreateFieldTable(lua_State *L, const char *const lst[]);
|
2020-11-17 12:14:45 +00:00
|
|
|
void LUA_HookNetArchive(lua_CFunction archFunc);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2020-12-04 08:30:08 +00:00
|
|
|
void LUA_PushTaggableObjectArray
|
|
|
|
( lua_State *L,
|
|
|
|
const char *field,
|
|
|
|
lua_CFunction iterator,
|
|
|
|
lua_CFunction indexer,
|
|
|
|
lua_CFunction counter,
|
|
|
|
taggroup_t *garray[],
|
|
|
|
size_t * max_elements,
|
|
|
|
void * element_array,
|
|
|
|
size_t sizeof_element,
|
|
|
|
const char *meta);
|
|
|
|
|
2023-10-28 09:06:30 +00:00
|
|
|
void LUA_SetCFunctionField(lua_State *L, const char *name, lua_CFunction value);
|
|
|
|
|
2023-10-27 18:17:27 +00:00
|
|
|
void LUA_RegisterUserdataMetatable(
|
|
|
|
lua_State *L,
|
|
|
|
const char *name,
|
|
|
|
lua_CFunction get,
|
|
|
|
lua_CFunction set,
|
|
|
|
lua_CFunction len
|
|
|
|
);
|
|
|
|
|
2023-10-27 22:24:04 +00:00
|
|
|
void LUA_CreateAndSetMetatable(
|
|
|
|
lua_State *L,
|
|
|
|
lua_CFunction get,
|
|
|
|
lua_CFunction set,
|
|
|
|
lua_CFunction len,
|
|
|
|
boolean keep
|
|
|
|
);
|
|
|
|
|
|
|
|
void LUA_CreateAndSetUserdataField(
|
|
|
|
lua_State *L,
|
|
|
|
int index,
|
|
|
|
const char *name,
|
|
|
|
lua_CFunction get,
|
|
|
|
lua_CFunction set,
|
|
|
|
lua_CFunction len,
|
|
|
|
boolean keep
|
|
|
|
);
|
|
|
|
|
|
|
|
void LUA_RegisterGlobalUserdata(
|
|
|
|
lua_State *L,
|
|
|
|
const char *name,
|
|
|
|
lua_CFunction get,
|
|
|
|
lua_CFunction set,
|
|
|
|
lua_CFunction len
|
|
|
|
);
|
|
|
|
|
2020-12-04 08:30:08 +00:00
|
|
|
void LUA_InsertTaggroupIterator
|
|
|
|
( lua_State *L,
|
|
|
|
taggroup_t *garray[],
|
|
|
|
size_t * max_elements,
|
|
|
|
void * element_array,
|
|
|
|
size_t sizeof_element,
|
|
|
|
const char * meta);
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LPUSHED_NIL,
|
|
|
|
LPUSHED_NEW,
|
|
|
|
LPUSHED_EXISTING,
|
|
|
|
} lpushed_t;
|
|
|
|
|
|
|
|
void LUA_PushUserdata(lua_State *L, void *data, const char *meta);
|
|
|
|
lpushed_t LUA_RawPushUserdata(lua_State *L, void *data);
|
|
|
|
|
|
|
|
void LUA_InvalidateUserdata(void *data);
|
|
|
|
|
|
|
|
void LUA_InvalidateLevel(void);
|
|
|
|
void LUA_InvalidateMapthings(void);
|
|
|
|
void LUA_InvalidatePlayer(player_t *player);
|
|
|
|
|
2014-04-14 05:14:58 +00:00
|
|
|
// Console wrapper
|
|
|
|
void COM_Lua_f(void);
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
#define LUA_ErrInvalid(L, type) luaL_error(L, "accessed " type " doesn't exist anymore, please check 'valid' before using " type ".");
|
|
|
|
|
2020-12-04 21:47:22 +00:00
|
|
|
#define LUA_ErrSetDirectly(L, type, field) luaL_error(L, type " field " LUA_QL(field) " cannot be set directly.")
|
|
|
|
|
2016-03-09 06:15:26 +00:00
|
|
|
// Deprecation warnings
|
|
|
|
// Shows once upon use. Then doesn't show again.
|
|
|
|
#define LUA_Deprecated(L,this_func,use_instead)\
|
|
|
|
{\
|
|
|
|
static UINT8 seen = 0;\
|
|
|
|
if (!seen) {\
|
|
|
|
seen = 1;\
|
|
|
|
CONS_Alert(CONS_WARNING,"\"%s\" is deprecated and will be removed.\nUse \"%s\" instead.\n", this_func, use_instead);\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
2016-05-11 21:33:50 +00:00
|
|
|
// Warnings about incorrect function usage.
|
|
|
|
// Shows once, then never again, like deprecation
|
|
|
|
#define LUA_UsageWarning(L, warningmsg)\
|
|
|
|
{\
|
|
|
|
static UINT8 seen = 0;\
|
|
|
|
if (!seen) {\
|
|
|
|
seen = 1;\
|
|
|
|
CONS_Alert(CONS_WARNING,"%s\n", warningmsg);\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
2016-11-24 21:11:44 +00:00
|
|
|
// uncomment if you want seg_t/node_t in Lua
|
|
|
|
// #define HAVE_LUA_SEGS
|
|
|
|
|
2020-01-16 03:13:41 +00:00
|
|
|
#define ISINLEVEL \
|
|
|
|
(gamestate == GS_LEVEL || titlemapinaction)
|
|
|
|
|
|
|
|
#define INLEVEL if (! ISINLEVEL)\
|
2019-07-30 16:57:57 +00:00
|
|
|
return luaL_error(L, "This can only be used in a level!");
|
2020-12-04 08:30:08 +00:00
|
|
|
|
|
|
|
#endif/*LUA_SCRIPT_H*/
|