Add raylua.listfiles()
This commit is contained in:
parent
3d7a4ceaf0
commit
e9586bed80
10
src/raylua.c
10
src/raylua.c
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
extern const char *raylua_boot_str;
|
extern const char *raylua_boot_str;
|
||||||
|
|
||||||
void raylua_boot(lua_State *L, lua_CFunction loadfile, bool repl)
|
void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles, bool repl)
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
||||||
|
@ -49,6 +49,12 @@ void raylua_boot(lua_State *L, lua_CFunction loadfile, bool repl)
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (listfiles) {
|
||||||
|
lua_pushstring(L, "listfiles");
|
||||||
|
lua_pushcfunction(L, listfiles);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
}
|
||||||
|
|
||||||
lua_pushstring(L, "bind_entries");
|
lua_pushstring(L, "bind_entries");
|
||||||
lua_pushlightuserdata(L, raylua_entries);
|
lua_pushlightuserdata(L, raylua_entries);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
@ -65,6 +71,6 @@ void raylua_boot(lua_State *L, lua_CFunction loadfile, bool repl)
|
||||||
|
|
||||||
int luaopen_raylua(lua_State *L)
|
int luaopen_raylua(lua_State *L)
|
||||||
{
|
{
|
||||||
raylua_boot(L, NULL, false);
|
raylua_boot(L, NULL, NULL, false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
|
||||||
void raylua_boot(lua_State *L, lua_CFunction loadfile, bool repl);
|
void raylua_boot(lua_State *L, lua_CFunction loadfile, lua_CFunction listfiles, bool repl);
|
||||||
|
|
||||||
/* raylua_boot alias to allow direct loading */
|
/* raylua_boot alias to allow direct loading */
|
||||||
int luaopen_raylua(lua_State *L);
|
int luaopen_raylua(lua_State *L);
|
||||||
|
|
|
@ -67,6 +67,25 @@ int raylua_loadfile(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int raylua_listfiles(lua_State *L)
|
||||||
|
{
|
||||||
|
size_t count = mz_zip_reader_get_num_files(&zip_file);
|
||||||
|
char filename[1024];
|
||||||
|
|
||||||
|
lua_createtable(L, count, 0);
|
||||||
|
|
||||||
|
size_t i = 0;
|
||||||
|
while (i < count) {
|
||||||
|
mz_zip_reader_get_filename(&zip_file, i, filename, sizeof(filename));
|
||||||
|
lua_pushstring(L, filename);
|
||||||
|
|
||||||
|
lua_rawseti(L, -2, i + 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char *raylua_loadFileData(const char *path, unsigned int *out_size)
|
unsigned char *raylua_loadFileData(const char *path, unsigned int *out_size)
|
||||||
{
|
{
|
||||||
int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0);
|
int index = mz_zip_reader_locate_file(&zip_file, path, NULL, 0);
|
||||||
|
@ -178,7 +197,7 @@ int main(int argc, const char **argv)
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* Boot on payload. */
|
/* Boot on payload. */
|
||||||
raylua_boot(L, raylua_loadfile, false);
|
raylua_boot(L, raylua_loadfile, raylua_listfiles, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
|
|
|
@ -44,7 +44,7 @@ int main(int argc, const char **argv)
|
||||||
|
|
||||||
lua_setglobal(L, "arg");
|
lua_setglobal(L, "arg");
|
||||||
|
|
||||||
raylua_boot(L, NULL, true);
|
raylua_boot(L, NULL, NULL, true);
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue