Merge branch 'main' into main

This commit is contained in:
Astazium 2026-10-15 16:19:06 +03:00 • committed by GitHub
commit bf59e520a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
109 changed files with 1908 additions and 474 deletions

View file

@ -104,6 +104,8 @@ void CameraControl::updateMouse(PlayerInput& input, int windowHeight) {
glm::vec3 CameraControl::updateCameraShaking(
const Hitbox& hitbox, float delta
) {
delta = glm::min(delta, 0.1f);
glm::vec3 offset {};
const float k = CAM_SHAKE_DELTA_K;
const float ov = CAM_SHAKE_OFFSET_Y;

View file

@ -165,6 +165,13 @@ static int l_container_set_interval(lua::State* L) {
static int l_move_into(lua::State* L) {
auto node = get_document_node(L, 1);
auto dest = get_document_node(L, 2);
if (dest.node == nullptr) {
return 0;
}
if (dest.node->isDescendantOf(node.node.get())) {
luaL_error(L, "unable to move element to its descendant");
return 0;
}
UINode::moveInto(
node.node, std::dynamic_pointer_cast<Container>(dest.node)
);

View file

@ -44,10 +44,13 @@ static int l_add_callback(lua::State* L) {
auto& input = engine->getInput();
if (pos != std::string::npos) {
std::string prefix = bindname.substr(0, pos);
auto prefix = std::string_view(bindname).substr(0, pos);
if (prefix == "key") {
auto key = input_util::keycode_from(bindname.substr(pos + 1));
handler = input.addKeyCallback(key, actual_callback);
} else if (prefix == "mouse") {
auto mouse = input_util::mousecode_from(bindname.substr(pos + 1));
handler = input.addMouseCallback(mouse, actual_callback);
}
}

View file

@ -266,8 +266,10 @@ static int l_peek(lua::State* L, network::Network& network) {
static int l_available(lua::State* L, network::Network& network) {
u64id_t id = lua::tointeger(L, 1);
if (auto connection = network.getConnection(id, false)) {
return lua::pushinteger(L, dynamic_cast<network::TcpConnection*>(connection)->available());
if (auto connection = dynamic_cast<network::ReadableConnection*>(
network.getConnection(id, false)
)) {
return lua::pushinteger(L, connection->available());
}
return 0;

View file

@ -30,7 +30,7 @@ static int push_xml(lua::State* L, const xml::xmlelement& elem) {
}
static std::unique_ptr<xml::xmlelement> toxml(lua::State* L) {
lua::getfield(L, TAG_ATTR);
lua::requirefield(L, TAG_ATTR);
auto tag = lua::require_lstring(L, -1);
lua::pop(L);
@ -39,6 +39,13 @@ static std::unique_ptr<xml::xmlelement> toxml(lua::State* L) {
for (int i = 0; i < length; i++) {
lua::rawgeti(L, i + 1);
if (lua::isstring(L, -1)) {
auto textElement = std::make_unique<xml::xmlelement>("#");
textElement->set("#", std::string(lua::require_lstring(L, -1)));
elem->add(std::move(textElement));
lua::pop(L);
continue;
}
elem->add(toxml(L));
lua::pop(L);
}

View file

@ -196,6 +196,10 @@ void lua::init_state(State* L, StateType stateType) {
if (stateType == StateType::GENERATOR) {
pushnil(L);
setglobal(L, "ffi");
static const char* removed_debug[] {
"getregistry", "getupvalue", "setupvalue", "getinfo", nullptr};
remove_lib_funcs(L, "debug", removed_debug);
}
}

View file

@ -263,7 +263,7 @@ runnable lua::create_runnable(State* L) {
};
}
KeyCallback lua::create_simple_handler(State* L) {
InputCallback lua::create_simple_handler(State* L) {
auto funcptr = create_lambda_handler(L);
return [=]() -> bool {
if (!get_from_registry(L, LAMBDAS_TABLE, *funcptr, false)) {

View file

@ -665,7 +665,7 @@ namespace lua {
}
runnable create_runnable(lua::State*);
KeyCallback create_simple_handler(lua::State*);
InputCallback create_simple_handler(lua::State*);
scripting::common_func create_lambda(lua::State*);
scripting::common_func create_lambda_nothrow(lua::State*);

View file

@ -99,14 +99,21 @@ template <typename T, T(tovalueFunc)(lua::State*, int)>
std::function<T()> create_supplier(
const scriptenv& env, const std::string& src, const std::string& file
) {
return [=]() {
return [=, errorLogged = false]() mutable {
lua::stackguard guard(lua::get_main_state());
if (auto L = process_callback(env, src, file)) {
if (lua::isfunction(L, -1)) {
lua::call_nothrow(L, 0);
if (lua::isfunction(L, -1) && !lua::call_nothrow(L, 0)) {
return T {};
}
try {
return tovalueFunc(L, -1);
} catch (const std::exception& err) {
if (!errorLogged) {
logger.error() << "supplier " << util::quote(src) << ": "
<< err.what();
errorLogged = true;
}
}
auto str = tovalueFunc(L, -1);
lua::pop(L);
return str;
}
return T {};
};
@ -158,16 +165,33 @@ int_array_consumer scripting::create_int_array_consumer(
vec2supplier scripting::create_vec2_supplier(
const scriptenv& env, const std::string& src, const std::string& file
) {
return [=]() {
if (auto L = process_callback(env, src, file)) {
if (lua::isfunction(L, -1)) {
lua::call_nothrow(L, 0);
return [=, errorLogged = false]() mutable {
auto L = lua::get_main_state();
lua::stackguard guard(L);
int top = lua::gettop(L);
if (process_callback(env, src, file)) {
if (lua::isfunction(L, -1) && !lua::call_nothrow(L, 0)) {
return glm::vec2(0, 0);
}
if (lua::gettop(L) - top < 2) {
if (!errorLogged) {
logger.error() << "supplier " << util::quote(src)
<< ": two numbers expected";
errorLogged = true;
}
return glm::vec2(0, 0);
}
try {
auto y = lua::tonumber(L, -1);
auto x = lua::tonumber(L, -2);
return glm::vec2(x, y);
} catch (const std::exception& err) {
if (!errorLogged) {
logger.error() << "supplier " << util::quote(src) << ": "
<< err.what();
errorLogged = true;
}
}
auto y = lua::tonumber(L, -1);
lua::pop(L);
auto x = lua::tonumber(L, -1);
lua::pop(L);
return glm::vec2(x, y);
}
return glm::vec2(0, 0);
};