- [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 "mini.h"
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static int cpp_newsurf(lua_State *L) {
|
static int cpp_newsurf(lua_State *L) {
|
||||||
int w = luaL_checknumber(L, 1);
|
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) {
|
static int cpp_exit(lua_State *L) {
|
||||||
exit();
|
exit();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -983,6 +997,8 @@ void push_lua_funcs() {
|
|||||||
lua_pushcfunction(L,cpp_configfolder); lua_setglobal(L, "configfolder");
|
lua_pushcfunction(L,cpp_configfolder); lua_setglobal(L, "configfolder");
|
||||||
|
|
||||||
lua_pushcfunction(L,cpp_turbo); lua_setglobal(L, "turbo");
|
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_pushcfunction(L,cpp_exit); lua_setglobal(L, "quit");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user