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
+6
View File
@@ -108,8 +108,14 @@ static int l_time_uptime(lua_State* L) {
return 1;
}
static int l_time_delta(lua_State* L) {
lua_pushnumber(L, scripting::engine->getDelta());
return 1;
}
static const luaL_Reg timelib [] = {
{"uptime", l_time_uptime},
{"delta", l_time_delta},
{NULL, NULL}
};
+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);
};
}
+6
View File
@@ -55,6 +55,12 @@ namespace scripting {
const std::string& file="<string>"
);
doubleconsumer create_number_consumer(
int env,
const std::string& src,
const std::string& file="<string>"
);
int_array_consumer create_int_array_consumer(
int env,
const std::string& src,