I can't remember what I did, but it was something cool
parent
c15309a5a0
commit
fd9603ce3f
|
@ -13,21 +13,20 @@
|
||||||
extern lua_State *g_L;
|
extern lua_State *g_L;
|
||||||
extern BOOL g_bLuaInitialized;
|
extern BOOL g_bLuaInitialized;
|
||||||
|
|
||||||
static const luaL_Reg gsLib_METHODS[] = {
|
typedef enum gsLuaType
|
||||||
{ "Print_Console", LUA_PrintConsole },
|
|
||||||
{ NULL, NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
{
|
||||||
LTYPE_INT,
|
LTYPE_INT,
|
||||||
LTYPE_STR
|
LTYPE_STRING,
|
||||||
|
LTYPE_FLOAT,
|
||||||
|
LTYPE_FUNC
|
||||||
} gsLuaType;
|
} gsLuaType;
|
||||||
|
|
||||||
typedef union
|
typedef union gsLuaGlobal
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char *str;
|
char const *str;
|
||||||
|
float f;
|
||||||
|
lua_CFunction fn;
|
||||||
} gsLuaGlobal;
|
} gsLuaGlobal;
|
||||||
|
|
||||||
typedef struct gsLuaRegGlobal
|
typedef struct gsLuaRegGlobal
|
||||||
|
@ -37,13 +36,19 @@ typedef struct gsLuaRegGlobal
|
||||||
gsLuaType type;
|
gsLuaType type;
|
||||||
} gsLuaRegGlobal;
|
} gsLuaRegGlobal;
|
||||||
|
|
||||||
static gsLuaRegGlobal const gsLib_GLOBALS[] = {
|
enum
|
||||||
{ "at_notice", at_notice, LTYPE_INT },
|
{
|
||||||
{ "at_console", at_console, LTYPE_INT },
|
LF_PRINT_CONSOLE = 6
|
||||||
{ "at_aiconsole", at_aiconsole, LTYPE_INT },
|
};
|
||||||
{ "at_warning", at_warning, LTYPE_INT },
|
|
||||||
{ "at_error", at_error, LTYPE_INT },
|
static gsLuaRegGlobal gsLib_GLOBALS[] = {
|
||||||
{ "at_logged", at_logged, LTYPE_INT },
|
{ "at_notice", at_notice, LTYPE_INT },
|
||||||
|
{ "at_console", at_console, LTYPE_INT },
|
||||||
|
{ "at_aiconsole", at_aiconsole, LTYPE_INT },
|
||||||
|
{ "at_warning", at_warning, LTYPE_INT },
|
||||||
|
{ "at_error", at_error, LTYPE_INT },
|
||||||
|
{ "at_logged", at_logged, LTYPE_INT },
|
||||||
|
{ "Print_Console", 0, LTYPE_FUNC },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,11 +58,12 @@ static gsLuaRegGlobal const gsLib_GLOBALS[] = {
|
||||||
|
|
||||||
void LuaInit(void)
|
void LuaInit(void)
|
||||||
{
|
{
|
||||||
|
gsLib_GLOBALS[LF_PRINT_CONSOLE].value.fn = LUA_PrintConsole;
|
||||||
|
|
||||||
g_L = luaL_newstate();
|
g_L = luaL_newstate();
|
||||||
g_bLuaInitialized = TRUE;
|
g_bLuaInitialized = TRUE;
|
||||||
ALERT(at_console, "[HLua] Lua initialized.\n");
|
ALERT(at_console, "[HLua] Lua initialized.\n");
|
||||||
|
|
||||||
LuaRegisterFunctions();
|
|
||||||
LuaRegisterGlobals();
|
LuaRegisterGlobals();
|
||||||
|
|
||||||
if(luaL_dostring(g_L, "Print_Console(at_console, \"[HLua::Lua] Initialization success!\");") == TRUE)
|
if(luaL_dostring(g_L, "Print_Console(at_console, \"[HLua::Lua] Initialization success!\");") == TRUE)
|
||||||
|
@ -77,7 +83,7 @@ void LuaQuit(void)
|
||||||
|
|
||||||
void LuaCheckNull(void const *vpToCheck)
|
void LuaCheckNull(void const *vpToCheck)
|
||||||
{
|
{
|
||||||
if (vpToCheck == NULL)
|
if(vpToCheck == NULL)
|
||||||
{
|
{
|
||||||
LuaError("[HLua] Null pointer exception!\n");
|
LuaError("[HLua] Null pointer exception!\n");
|
||||||
}
|
}
|
||||||
|
@ -148,21 +154,6 @@ void LuaParseScripts(void)
|
||||||
|
|
||||||
// --- Binded lua functions and globals ---
|
// --- Binded lua functions and globals ---
|
||||||
|
|
||||||
void LuaRegisterFunctions(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
ALERT(at_console, "[HLua] Registering functions.\n");
|
|
||||||
|
|
||||||
for(i = 0; i < MAX_LUA_LIB_FUNCS; i++)
|
|
||||||
{
|
|
||||||
if(gsLib_METHODS[i].name == NULL && gsLib_METHODS[i].func == NULL) break;
|
|
||||||
|
|
||||||
lua_register(g_L, gsLib_METHODS[i].name, gsLib_METHODS[i].func);
|
|
||||||
}
|
|
||||||
|
|
||||||
ALERT(at_console, "[HLua] Register success, got %d functions.\n", i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LuaRegisterGlobals(void)
|
void LuaRegisterGlobals(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -175,7 +166,9 @@ void LuaRegisterGlobals(void)
|
||||||
switch(gsLib_GLOBALS[i].type)
|
switch(gsLib_GLOBALS[i].type)
|
||||||
{
|
{
|
||||||
case LTYPE_INT: lua_pushnumber(g_L, gsLib_GLOBALS[i].value.i); break;
|
case LTYPE_INT: lua_pushnumber(g_L, gsLib_GLOBALS[i].value.i); break;
|
||||||
case LTYPE_STR: lua_pushstring(g_L, gsLib_GLOBALS[i].value.str); break;
|
case LTYPE_STRING: lua_pushstring(g_L, gsLib_GLOBALS[i].value.str); break;
|
||||||
|
case LTYPE_FLOAT: lua_pushnumber(g_L, gsLib_GLOBALS[i].value.f); break;
|
||||||
|
case LTYPE_FUNC: lua_pushcfunction(g_L, gsLib_GLOBALS[i].value.fn); break;
|
||||||
default: LuaError("[HLua] Invalid type in global initializer!\n"); return;
|
default: LuaError("[HLua] Invalid type in global initializer!\n"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
void LuaInit(void);
|
void LuaInit(void);
|
||||||
void LuaQuit(void);
|
void LuaQuit(void);
|
||||||
void LuaCheckNull(void const *vpToCheck);
|
void LuaCheckNull(void const *vpToCheck);
|
||||||
void LuaRegisterFunctions(void);
|
|
||||||
void LuaRegisterGlobals(void);
|
void LuaRegisterGlobals(void);
|
||||||
void LuaParseScripts(void);
|
void LuaParseScripts(void);
|
||||||
void LuaRunScript(char *szFilename);
|
void LuaRunScript(char *szFilename);
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;QUIVER;VOXEL;QUAKE2;VALVE_DLL;CLIENT_WEAPONS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;QUIVER;VOXEL;QUAKE2;VALVE_DLL;CLIENT_WEAPONS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
||||||
<AdditionalIncludeDirectories>..\..\dlls;..\..\engine;..\..\common;..\..\pm_shared;..\..\game_shared;..\..\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\dlls;..\..\engine;..\..\common;..\..\pm_shared;..\..\game_shared;..\..\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||||
|
|
Loading…
Reference in New Issue