Merge branch 'main' into devtools
This commit is contained in:
@@ -140,6 +140,37 @@ static int l_file_write_bytes(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
static int l_file_list_all_res(lua_State* L, const std::string& path) {
|
||||
auto files = scripting::engine->getResPaths()->listdirRaw(path);
|
||||
lua_createtable(L, files.size(), 0);
|
||||
for (size_t i = 0; i < files.size(); i++) {
|
||||
lua_pushstring(L, files[i].c_str());
|
||||
lua_rawseti(L, -2, i+1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_file_list(lua_State* L) {
|
||||
std::string dirname = lua_tostring(L, 1);
|
||||
if (dirname.find(':') == std::string::npos) {
|
||||
return l_file_list_all_res(L, dirname);
|
||||
}
|
||||
fs::path path = resolve_path(L, dirname);
|
||||
if (!fs::is_directory(path)) {
|
||||
throw std::runtime_error(util::quote(path.u8string())+" is not a directory");
|
||||
}
|
||||
lua_createtable(L, 0, 0);
|
||||
size_t index = 1;
|
||||
for (auto& entry : fs::directory_iterator(path)) {
|
||||
auto name = entry.path().filename().u8string();
|
||||
auto file = dirname + "/" + name;
|
||||
lua_pushstring(L, file.c_str());
|
||||
lua_rawseti(L, -2, index);
|
||||
index++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg filelib [] = {
|
||||
{"resolve", lua_wrap_errors<l_file_resolve>},
|
||||
{"find", lua_wrap_errors<l_file_find>},
|
||||
@@ -153,5 +184,6 @@ const luaL_Reg filelib [] = {
|
||||
{"mkdirs", lua_wrap_errors<l_file_mkdirs>},
|
||||
{"read_bytes", lua_wrap_errors<l_file_read_bytes>},
|
||||
{"write_bytes", lua_wrap_errors<l_file_write_bytes>},
|
||||
{"list", lua_wrap_errors<l_file_list>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -204,6 +204,13 @@ static int p_get_text(UINode* node) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_editable(UINode* node) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
return state->pushboolean(box->isEditable());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_add(UINode* node) {
|
||||
if (dynamic_cast<Container*>(node)) {
|
||||
return state->pushcfunction(l_container_add);
|
||||
@@ -268,6 +275,7 @@ static int l_gui_getattr(lua_State* L) {
|
||||
{"placeholder", p_get_placeholder},
|
||||
{"valid", p_is_valid},
|
||||
{"text", p_get_text},
|
||||
{"editable", p_get_editable},
|
||||
{"value", p_get_value},
|
||||
{"min", p_get_min},
|
||||
{"max", p_get_max},
|
||||
@@ -325,6 +333,11 @@ static void p_set_text(UINode* node, int idx) {
|
||||
box->setText(util::str2wstr_utf8(state->tostring(idx)));
|
||||
}
|
||||
}
|
||||
static void p_set_editable(UINode* node, int idx) {
|
||||
if (auto box = dynamic_cast<TextBox*>(node)) {
|
||||
box->setEditable(state->toboolean(idx));
|
||||
}
|
||||
}
|
||||
static void p_set_value(UINode* node, int idx) {
|
||||
if (auto bar = dynamic_cast<TrackBar*>(node)) {
|
||||
bar->setValue(state->tonumber(idx));
|
||||
@@ -397,6 +410,7 @@ static int l_gui_setattr(lua_State* L) {
|
||||
{"enabled", p_set_enabled},
|
||||
{"placeholder", p_set_placeholder},
|
||||
{"text", p_set_text},
|
||||
{"editable", p_set_editable},
|
||||
{"value", p_set_value},
|
||||
{"min", p_set_min},
|
||||
{"max", p_set_max},
|
||||
@@ -459,8 +473,7 @@ static int l_gui_get_locales_info(lua_State* L) {
|
||||
}
|
||||
|
||||
static int l_gui_getviewport(lua_State* L) {
|
||||
lua::pushvec2_arr(L, scripting::engine->getGUI()->getContainer()->getSize());
|
||||
return 1;
|
||||
return lua::pushvec2_arr(L, scripting::engine->getGUI()->getContainer()->getSize());
|
||||
}
|
||||
|
||||
const luaL_Reg guilib [] = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "api_lua.hpp"
|
||||
#include "lua_util.hpp"
|
||||
#include "lua_commons.hpp"
|
||||
#include "LuaState.hpp"
|
||||
#include "../scripting.hpp"
|
||||
@@ -39,9 +40,14 @@ static int l_add_callback(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_mouse_pos(lua_State* L) {
|
||||
return lua::pushvec2_arr(L, Events::cursor);
|
||||
}
|
||||
|
||||
const luaL_Reg inputlib [] = {
|
||||
{"keycode", lua_wrap_errors<l_keycode>},
|
||||
{"add_callback", lua_wrap_errors<l_add_callback>},
|
||||
{"get_mouse_pos", lua_wrap_errors<l_get_mouse_pos>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user