gui: more xml and lua support

This commit is contained in:
MihailRis
2024-02-14 00:31:45 +03:00
parent ef0d4d69e4
commit c6bd52eed2
10 changed files with 110 additions and 30 deletions
+34 -18
View File
@@ -70,21 +70,42 @@ runnable scripting::create_runnable(
};
}
static bool processCallback(
int env,
const std::string& src,
const std::string& file
) {
try {
return state->eval(env, src, file) != 0;
} catch (lua::luaerror err) {
std::cerr << err.what() << std::endl;
return false;
}
}
wstringconsumer scripting::create_wstring_consumer(
int env,
const std::string& src,
const std::string& file
) {
return [=](const std::wstring& x){
try {
if (state->eval(env, src, file) == 0)
return;
} catch (lua::luaerror err) {
std::cerr << err.what() << std::endl;
return;
if (processCallback(env, src, file)) {
state->pushstring(util::wstr2str_utf8(x));
state->callNoThrow(1);
}
};
}
doubleconsumer scripting::create_number_consumer(
int env,
const std::string& src,
const std::string& file
) {
return [=](double x){
if (processCallback(env, src, file)) {
state->pushnumber(x);
state->callNoThrow(1);
}
state->pushstring(util::wstr2str_utf8(x));
state->callNoThrow(1);
};
}
@@ -94,17 +115,12 @@ int_array_consumer scripting::create_int_array_consumer(
const std::string& file
) {
return [=](const int arr[], size_t len){
try {
if (state->eval(env, src, file) == 0)
return;
} catch (lua::luaerror err) {
std::cerr << err.what() << std::endl;
return;
if (processCallback(env, src, file)) {
for (uint i = 0; i < len; i++) {
state->pushinteger(arr[i]);
}
state->callNoThrow(len);
}
for (uint i = 0; i < len; i++) {
state->pushinteger(arr[i]);
}
state->callNoThrow(len);
};
}