2012-11-10 20:59:00 +00:00
|
|
|
/* The Lunatic Interpreter, part of EDuke32. Common, engine-side stuff. */
|
|
|
|
|
|
|
|
#ifndef ENGINE_LUNATIC_H_
|
|
|
|
#define ENGINE_LUNATIC_H_
|
|
|
|
|
2014-01-31 21:13:03 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-10-16 19:43:06 +00:00
|
|
|
#ifdef USE_LUAJIT_2_1
|
|
|
|
# include <luajit-2.1/lua.h>
|
|
|
|
#else
|
|
|
|
# include <luajit-2.0/lua.h>
|
|
|
|
#endif
|
2012-11-10 20:59:00 +00:00
|
|
|
|
2014-01-31 21:13:03 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-10 20:59:00 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
lua_State *L;
|
|
|
|
} L_State;
|
|
|
|
|
|
|
|
|
|
|
|
// -- functions --
|
|
|
|
|
|
|
|
// helpers taking the lua_State directly:
|
2012-12-29 15:21:32 +00:00
|
|
|
void L_PushDebugTraceback(lua_State *L);
|
2012-11-10 20:59:00 +00:00
|
|
|
void L_CheckAndRegisterFunction(lua_State *L, void *regkeyaddr);
|
2013-01-01 15:24:11 +00:00
|
|
|
int L_HandleError(lua_State *L, int errcode, void (*ErrorPrintFunc)(const char *));
|
2012-11-10 20:59:00 +00:00
|
|
|
|
2012-12-25 16:13:41 +00:00
|
|
|
// Callback on Lua error. <str> must be used immediately or strdup'd.
|
2014-01-31 21:13:03 +00:00
|
|
|
extern void (*L_ErrorFunc)(const char *str);
|
2013-01-01 15:24:11 +00:00
|
|
|
// Out-of-memory handler, supposed to terminate the host program.
|
2014-01-31 21:13:03 +00:00
|
|
|
extern void (*L_OutOfMemFunc)(void);
|
2012-12-25 16:13:41 +00:00
|
|
|
|
2012-11-10 20:59:00 +00:00
|
|
|
int L_CreateState(L_State *estate, const char *name, void (*StateSetupFunc)(lua_State *));
|
|
|
|
void L_DestroyState(L_State *estate);
|
|
|
|
int L_RunOnce(L_State *estate, const char *fn);
|
2013-02-24 16:05:31 +00:00
|
|
|
int L_RunString(L_State *estate, char *buf, int dofreebuf, int size, const char *name);
|
2012-11-10 20:59:00 +00:00
|
|
|
|
|
|
|
static inline int L_IsInitialized(const L_State *estate) { return (estate->L != NULL); }
|
|
|
|
|
|
|
|
#endif
|