28 #include "../../shared/cxx.h"
29 #include "../../shared/defines.h"
30 #include "../../shared/shared.h"
31 #include "../../common/hashtable.h"
32 #include "../../common/filesys.h"
51 const char*
name = lua_tostring (L, -1);
55 memset(module, 0,
sizeof(module));
56 Com_sprintf(module,
sizeof(module),
"ufos/ui/%s", name);
57 memset(errmsg, 0,
sizeof(errmsg));
64 if (luaL_loadbuffer (L, (
const char*) buffer, len, module) == 0) {
69 sprintf(errmsg,
"custom loader error - cannot load module named [%s]\n", module);
70 lua_pushstring (L, errmsg);
75 sprintf(errmsg,
"custom loader error - cannot find module named [%s]\n", module);
76 lua_pushstring (L, errmsg);
89 int pos = lua_gettop (L);
92 lua_getfield (L, LUA_GLOBALSINDEX,
"package");
94 lua_getfield (L, -1,
"loaders");
106 while (lua_next (L, -2) != 0) {
114 lua_pushinteger (L, nloaders + 1);
172 int regvalue = (
int) fnc;
174 int len = strlen (key);
176 HASH_Insert (cl_callback, key, len, ®value,
sizeof(regvalue));
179 Com_Printf(
"CL_RegisterCallback: lua callback registration error: script name has zero length!\n");
192 void *value =
HASH_Get(cl_callback, key, strlen (key));
194 int regvalue = * ((
int*)value);
195 lua_rawgeti (L, LUA_REGISTRYINDEX, regvalue);
196 if (lua_pcall (L, 0, 0, 0) != 0) {
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
lua_State * CL_GetLuaState(void)
Returns the lua state for the client side.
void CL_ShutdownLua(void)
Shutdown the ui-lua interfacing environment.
void HASH_DeleteTable(hashTable_s **t)
Deletes a hash table and sets the pointer to NULL.
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void Com_Printf(const char *const fmt,...)
hashTable_s * HASH_NewTable(bool ownsKeys, bool ownsValues, bool duplicateOverwrite)
Creates a new hash table and sets it initial capacity.
int luaopen_ufo(lua_State *L)
The hash table structure, contains an array of buckets being indexed by the hash function.
void CL_InitLua(void)
Initializes the ui-lua interfacing environment.
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 files...
void * HASH_Get(hashTable_s *t, const void *key, int nkey)
Returns the value for a given key.
static int CL_UfoModuleLoader(lua_State *L)
Loader that enables the lua files to access .ufo files through the ufo filesystem.
QGL_EXTERN GLuint GLchar GLuint * len
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
int LUA_FUNCTION
callback signatures for functions defined in Lua
void CL_ExecuteCallback(lua_State *L, const char *key)
Calls the registered lua onload callback function.
void CL_RegisterCallback(const char *key, LUA_FUNCTION fnc)
Registers a lua callback function with a key.
bool HASH_Insert(hashTable_s *t, const void *key, int nkey, const void *value, int nvalue)
Inserts a new value with given key into the hash table.
hashTable_s * cl_callback