Merge branch 'main' into animation

This commit is contained in:
MihailRis 2026-08-22 00:36:25 +03:00
commit d20e9fcb40
18 changed files with 242 additions and 124 deletions

View file

@ -92,6 +92,17 @@ static int l_reconfig_packs(lua::State* L) {
return 0;
}
/// @brief Get current content packs configuration
static int l_get_content(lua::State* L) {
const auto& configuration = content_control->getContentPacks();
lua::createtable(L, configuration.size(), 0);
for (int i = 0; i < configuration.size(); i++) {
lua::pushlstring(L, configuration[i].id);
lua::rawseti(L, i + 1);
}
return 1;
}
/// @brief Get content sources list
static int l_get_content_sources(lua::State* L) {
const auto& sources = engine->getContentControl().getContentSources();
@ -453,6 +464,7 @@ const luaL_Reg applib[] = {
{"load_content", lua::wrap<l_load_content>},
{"reset_content", lua::wrap<l_reset_content>},
{"reconfig_packs", lua::wrap<l_reconfig_packs>},
{"get_content", lua::wrap<l_get_content>},
{"get_content_sources", lua::wrap<l_get_content_sources>},
{"set_content_sources", lua::wrap<l_set_content_sources>},
{"reset_content_sources", lua::wrap<l_reset_content_sources>},

View file

@ -1,5 +1,6 @@
#include "engine/Engine.hpp"
#include "api_lua.hpp"
#include "engine/Engine.hpp"
#include <ctime>
using namespace scripting;
@ -20,11 +21,18 @@ static int l_utc_time(lua::State* L) {
return lua::pushnumber(L, std::time(nullptr));
}
static int l_precise_utc_time(lua::State* L) {
auto now = std::chrono::steady_clock::now();
return lua::pushnumber(
L, std::chrono::duration<double>(now.time_since_epoch()).count()
);
}
static int l_local_time(lua::State* L) {
std::time_t t = std::time(nullptr);
std::tm gmt_tm{};
std::tm local_tm{};
std::tm gmt_tm {};
std::tm local_tm {};
#if defined(USE_MSVC_TIME_SAFE)
gmtime_s(&gmt_tm, &t);
@ -44,8 +52,8 @@ static int l_local_time(lua::State* L) {
static int l_utc_offset(lua::State* L) {
std::time_t t = std::time(nullptr);
std::tm gmt_tm{};
std::tm local_tm{};
std::tm gmt_tm {};
std::tm local_tm {};
#if defined(USE_MSVC_TIME_SAFE)
gmtime_s(&gmt_tm, &t);
@ -74,6 +82,7 @@ const luaL_Reg timelib[] = {
{"uptime", lua::wrap<l_uptime>},
{"delta", lua::wrap<l_delta>},
{"utc_time", lua::wrap<l_utc_time>},
{"precise_utc_time", lua::wrap<l_precise_utc_time>},
{"utc_offset", lua::wrap<l_utc_offset>},
{"local_time", lua::wrap<l_local_time>},
{"precise_time", lua::wrap<l_precise_time>},

View file

@ -74,6 +74,11 @@ static void create_libs(State* L, StateType stateType) {
getglobal(L, "__vc_app");
setregistry(L, "app");
createtable(L, 0, 0);
pushvalue(L, -1);
setglobal(L, "__vc_internals");
setregistry(L, "internals");
if (stateType == StateType::SCRIPT) {
getregistry(L, "app");
setglobal(L, "app");

View file

@ -288,7 +288,23 @@ void scripting::on_content_load(Content* content) {
lua::setfield(L, "properties");
lua::pop(L);
}
load_script("post_content.lua", true);
lua::getregistry(L, "app");
lua::setglobal(L, "__vc_app");
lua::getregistry(L, "internals");
lua::setglobal(L, "__vc_internals");
try {
load_script("post_content.lua", true);
} catch (const std::exception&) {
lua::pushnil(L);
lua::setglobal(L, "__vc_app");
throw;
}
lua::pushnil(L);
lua::setglobal(L, "__vc_app");
lua::pushnil(L);
lua::setglobal(L, "__vc_internals");
load_script("stdcmd.lua", true);
}