diff --git a/lua.cpp b/lua.cpp index 77728bf..893dc79 100644 --- a/lua.cpp +++ b/lua.cpp @@ -3,6 +3,9 @@ #include "mini.h" #include "jfile.h" +#include +namespace fs = std::filesystem; + extern "C" { static int cpp_newsurf(lua_State *L) { int w = luaL_checknumber(L, 1); @@ -855,6 +858,17 @@ extern "C" { } } + static int cpp_dir(lua_State *L) { + lua_newtable(L); + int i=1; + for (const auto& entry : fs::directory_iterator("./data")) { + lua_pushstring(L, entry.path().u8string().c_str()); + lua_rawseti(L, -2, i++); + } + + return 1; + } + static int cpp_exit(lua_State *L) { exit(); return 0; @@ -983,6 +997,8 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_configfolder); lua_setglobal(L, "configfolder"); lua_pushcfunction(L,cpp_turbo); lua_setglobal(L, "turbo"); + + lua_pushcfunction(L,cpp_dir); lua_setglobal(L, "dir"); lua_pushcfunction(L,cpp_exit); lua_setglobal(L, "quit");