VERSIÓ 1.3.15
- [NEW] mouse.dblclick() - [FIX] de vegades no pillava be la rodeta del ratolí - [NEW] sys.dir() torna el contingut del directori primer les carpetes, i tot ordenat alfabèticament - [WIP] Treballant en ferramentes
This commit is contained in:
40
lua.cpp
40
lua.cpp
@@ -4,6 +4,9 @@
|
||||
#include "jfile.h"
|
||||
#include "log.h"
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
extern "C" {
|
||||
@@ -723,23 +726,38 @@ extern "C" {
|
||||
std::string path = "./data";
|
||||
if (lua_gettop(L) > 0) path = luaL_checkstring(L, 1);
|
||||
|
||||
lua_newtable(L);
|
||||
int i=1;
|
||||
|
||||
// Collect entries
|
||||
std::vector<fs::directory_entry> entries;
|
||||
for (const auto& entry : fs::directory_iterator(path)) {
|
||||
lua_newtable(L); // create subtable for this entry
|
||||
entries.push_back(entry);
|
||||
}
|
||||
|
||||
// name field
|
||||
lua_pushstring(L, entry.path().u8string().c_str());
|
||||
// Sort: directories first, then files; both alphabetically
|
||||
std::sort(entries.begin(), entries.end(),
|
||||
[](const fs::directory_entry& a, const fs::directory_entry& b) {
|
||||
bool adir = a.is_directory();
|
||||
bool bdir = b.is_directory();
|
||||
if (adir != bdir) return adir > bdir; // directories before files
|
||||
return a.path().filename().string() < b.path().filename().string();
|
||||
});
|
||||
|
||||
// Build Lua table
|
||||
lua_newtable(L);
|
||||
int i = 1;
|
||||
for (const auto& entry : entries) {
|
||||
lua_newtable(L);
|
||||
|
||||
// name field (canonical absolute path)
|
||||
lua_pushstring(L, fs::canonical(entry.path()).u8string().c_str());
|
||||
lua_setfield(L, -2, "name");
|
||||
|
||||
// dir field (true if directory, false otherwise)
|
||||
// dir field
|
||||
lua_pushboolean(L, entry.is_directory());
|
||||
lua_setfield(L, -2, "dir");
|
||||
|
||||
// insert subtable into main table at index i
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -864,6 +882,11 @@ extern "C" {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mouse_dblclick(lua_State *L) {
|
||||
lua_pushboolean(L, doubleclick());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mouse_discard(lua_State *L) {
|
||||
mdiscard();
|
||||
return 0;
|
||||
@@ -1047,6 +1070,7 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_mouse_wheel); lua_setfield(L, -2, "wheel");
|
||||
lua_pushcfunction(L,cpp_mouse_down); lua_setfield(L, -2, "down");
|
||||
lua_pushcfunction(L,cpp_mouse_press); lua_setfield(L, -2, "press");
|
||||
lua_pushcfunction(L,cpp_mouse_dblclick); lua_setfield(L, -2, "dblclick");
|
||||
lua_pushcfunction(L,cpp_mouse_discard); lua_setfield(L, -2, "discard");
|
||||
|
||||
lua_pushinteger(L, 1); lua_setfield(L, -2, "LEFT");
|
||||
|
||||
Reference in New Issue
Block a user