- [NEW] funció dir() per a obtindre els arxius del directori "data"
This commit is contained in:
16
lua.cpp
16
lua.cpp
@@ -3,6 +3,9 @@
|
||||
#include "mini.h"
|
||||
#include "jfile.h"
|
||||
|
||||
#include <filesystem>
|
||||
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;
|
||||
@@ -984,6 +998,8 @@ void push_lua_funcs() {
|
||||
|
||||
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");
|
||||
|
||||
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
||||
|
||||
Reference in New Issue
Block a user