UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_lua.cpp File Reference

Basic lua initialization for the client. More...

#include "cl_lua.h"
#include "../../shared/cxx.h"
#include "../../shared/defines.h"
#include "../../shared/shared.h"
#include "../../common/hashtable.h"
#include "../../common/filesys.h"
Include dependency graph for cl_lua.cpp:

Go to the source code of this file.

Functions

int luaopen_ufo (lua_State *L)
static int CL_UfoModuleLoader (lua_State *L)
 Loader that enables the lua files to access .ufo files through the ufo filesystem.
static void CL_InsertModuleLoader (lua_State *L)
 This function adds loader to the lua table of module loaders that enables lua to access the ufo filesystem.
void CL_InitLua (void)
 Initializes the ui-lua interfacing environment.
void CL_ShutdownLua (void)
 Shutdown the ui-lua interfacing environment.
lua_State * CL_GetLuaState (void)
 Returns the lua state for the client side.
void CL_RegisterCallback (const char *key, LUA_FUNCTION fnc)
 Registers a lua callback function with a key.
void CL_ExecuteCallback (lua_State *L, const char *key)
 Calls the registered lua onload callback function.

Variables

lua_State * cl_luastate = nullptr
hashTable_scl_callback = nullptr

Detailed Description

Basic lua initialization for the client.

Definition in file cl_lua.cpp.

Function Documentation

◆ CL_ExecuteCallback()

void CL_ExecuteCallback ( lua_State * L,
const char * key )

Calls the registered lua onload callback function.

Parameters
[in]LThe lua state for calling lua.
[in]keyscript The name of the .ufo file holding the lua script.
Note
The signature of the lua function is without any paramters: function ().
If the signature changes, this function should change too.

Definition at line 194 of file cl_lua.cpp.

References cl_callback, cl_luastate, Com_Printf(), HASH_Get(), and key.

Referenced by UI_CallHandler_OnLoad().

◆ CL_GetLuaState()

◆ CL_InitLua()

◆ CL_InsertModuleLoader()

void CL_InsertModuleLoader ( lua_State * L)
static

This function adds loader to the lua table of module loaders that enables lua to access the ufo filesystem.

Definition at line 88 of file cl_lua.cpp.

References CL_UfoModuleLoader().

Referenced by CL_InitLua().

◆ CL_RegisterCallback()

void CL_RegisterCallback ( const char * key,
LUA_FUNCTION fnc )

Registers a lua callback function with a key.

Parameters
keyA key for finding the callback function by name, usually the script name.
fncA lua function registered in the lua registry index.

Definition at line 175 of file cl_lua.cpp.

References cl_callback, Com_Printf(), HASH_Insert(), int(), key, and len.

Referenced by UI_RegisterHandler_OnLoad().

◆ CL_ShutdownLua()

void CL_ShutdownLua ( void )

Shutdown the ui-lua interfacing environment.

Definition at line 155 of file cl_lua.cpp.

References cl_callback, cl_luastate, and HASH_DeleteTable().

Referenced by CL_InitLua(), CL_Shutdown(), and TEST_Shutdown().

◆ CL_UfoModuleLoader()

int CL_UfoModuleLoader ( lua_State * L)
static

Loader that enables the lua files to access .ufo files through the ufo filesystem.

Note
This function is called from inside the lua environment. If lua encounters a 'require' statement, it uses an internal table of loading functions to load the module.

Definition at line 47 of file cl_lua.cpp.

References Com_Printf(), Com_sprintf(), FS_LoadFile(), len, and name.

Referenced by CL_InsertModuleLoader().

◆ luaopen_ufo()

int luaopen_ufo ( lua_State * L)

Referenced by CL_InitLua().

Variable Documentation

◆ cl_callback

hashTable_s* cl_callback = nullptr

Definition at line 37 of file cl_lua.cpp.

Referenced by CL_ExecuteCallback(), CL_InitLua(), CL_RegisterCallback(), and CL_ShutdownLua().

◆ cl_luastate

lua_State* cl_luastate = nullptr

Definition at line 35 of file cl_lua.cpp.

Referenced by CL_ExecuteCallback(), CL_GetLuaState(), CL_InitLua(), and CL_ShutdownLua().