mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
LUI scripting fixes from iw6x
This commit is contained in:
parent
fa62a65c3b
commit
bbe3bd84a6
@ -1,6 +1,5 @@
|
||||
#include <std_include.hpp>
|
||||
#include "execution.hpp"
|
||||
#include "stack_isolation.hpp"
|
||||
#include "component/ui_scripting.hpp"
|
||||
|
||||
#include <utils/string.hpp>
|
||||
@ -41,8 +40,8 @@ namespace ui_scripting
|
||||
arguments call_script_function(const function& function, const arguments& arguments)
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
stack_isolation _;
|
||||
push_value(function);
|
||||
for (auto i = arguments.begin(); i != arguments.end(); ++i)
|
||||
{
|
||||
@ -67,8 +66,8 @@ namespace ui_scripting
|
||||
script_value get_field(const userdata& self, const script_value& key)
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
stack_isolation _;
|
||||
push_value(key);
|
||||
|
||||
const auto _1 = gsl::finally(&disable_error_hook);
|
||||
@ -93,8 +92,8 @@ namespace ui_scripting
|
||||
script_value get_field(const table& self, const script_value& key)
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
stack_isolation _;
|
||||
push_value(key);
|
||||
|
||||
const auto _1 = gsl::finally(&disable_error_hook);
|
||||
@ -119,8 +118,7 @@ namespace ui_scripting
|
||||
void set_field(const userdata& self, const script_value& key, const script_value& value)
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
|
||||
stack_isolation _;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
const auto _1 = gsl::finally(&disable_error_hook);
|
||||
enable_error_hook();
|
||||
@ -142,8 +140,7 @@ namespace ui_scripting
|
||||
void set_field(const table& self, const script_value& key, const script_value& value)
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
|
||||
stack_isolation _;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
const auto _1 = gsl::finally(&disable_error_hook);
|
||||
enable_error_hook();
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <std_include.hpp>
|
||||
#include "value_conversion.hpp"
|
||||
#include "../execution.hpp"
|
||||
#include "../stack_isolation.hpp"
|
||||
#include "../../../component/ui_scripting.hpp"
|
||||
|
||||
namespace ui_scripting::lua
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <std_include.hpp>
|
||||
#include "execution.hpp"
|
||||
#include "types.hpp"
|
||||
#include "stack_isolation.hpp"
|
||||
#include "script_value.hpp"
|
||||
|
||||
namespace ui_scripting
|
||||
@ -59,9 +58,10 @@ namespace ui_scripting
|
||||
script_value::script_value(const char* value)
|
||||
{
|
||||
game::hks::HksObject obj{};
|
||||
stack_isolation _;
|
||||
|
||||
const auto state = *game::hks::lua_state;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
game::hks::hksi_lua_pushlstring(state, value, (unsigned int)strlen(value));
|
||||
obj = state->m_apistack.top[-1];
|
||||
|
||||
@ -260,7 +260,7 @@ namespace ui_scripting
|
||||
template <>
|
||||
function script_value::get() const
|
||||
{
|
||||
return {this->get_raw().v.cClosure, this->get_raw().t};
|
||||
return { this->get_raw().v.cClosure, this->get_raw().t };
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
|
@ -1,30 +0,0 @@
|
||||
#include <std_include.hpp>
|
||||
#include "stack_isolation.hpp"
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
stack_isolation::stack_isolation()
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
|
||||
this->top_ = state->m_apistack.top;
|
||||
this->base_ = state->m_apistack.base;
|
||||
this->alloc_top_ = state->m_apistack.alloc_top;
|
||||
this->bottom_ = state->m_apistack.bottom;
|
||||
|
||||
state->m_apistack.top = this->stack_;
|
||||
state->m_apistack.base = state->m_apistack.top;
|
||||
state->m_apistack.alloc_top = &this->stack_[ARRAYSIZE(this->stack_) - 1];
|
||||
state->m_apistack.bottom = state->m_apistack.top;
|
||||
}
|
||||
|
||||
stack_isolation::~stack_isolation()
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
|
||||
state->m_apistack.top = this->top_;
|
||||
state->m_apistack.base = this->base_;
|
||||
state->m_apistack.alloc_top = this->alloc_top_;
|
||||
state->m_apistack.bottom = this->bottom_;
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
#include "game/game.hpp"
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
class stack_isolation final
|
||||
{
|
||||
public:
|
||||
stack_isolation();
|
||||
~stack_isolation();
|
||||
|
||||
stack_isolation(stack_isolation&&) = delete;
|
||||
stack_isolation(const stack_isolation&) = delete;
|
||||
stack_isolation& operator=(stack_isolation&&) = delete;
|
||||
stack_isolation& operator=(const stack_isolation&) = delete;
|
||||
|
||||
private:
|
||||
game::hks::HksObject stack_[512]{};
|
||||
|
||||
game::hks::HksObject* top_;
|
||||
game::hks::HksObject* base_;
|
||||
game::hks::HksObject* alloc_top_;
|
||||
game::hks::HksObject* bottom_;
|
||||
};
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
#include <std_include.hpp>
|
||||
#include "types.hpp"
|
||||
#include "execution.hpp"
|
||||
#include "stack_isolation.hpp"
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
@ -21,6 +20,72 @@ namespace ui_scripting
|
||||
userdata::userdata(void* ptr_)
|
||||
: ptr(ptr_)
|
||||
{
|
||||
this->add();
|
||||
}
|
||||
|
||||
userdata::userdata(const userdata& other)
|
||||
{
|
||||
this->operator=(other);
|
||||
}
|
||||
|
||||
userdata::userdata(userdata&& other) noexcept
|
||||
{
|
||||
this->ptr = other.ptr;
|
||||
this->ref = other.ref;
|
||||
other.ref = 0;
|
||||
}
|
||||
|
||||
userdata::~userdata()
|
||||
{
|
||||
this->release();
|
||||
}
|
||||
|
||||
userdata& userdata::operator=(const userdata& other)
|
||||
{
|
||||
if (&other != this)
|
||||
{
|
||||
this->release();
|
||||
this->ptr = other.ptr;
|
||||
this->ref = other.ref;
|
||||
this->add();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
userdata& userdata::operator=(userdata&& other) noexcept
|
||||
{
|
||||
if (&other != this)
|
||||
{
|
||||
this->release();
|
||||
this->ptr = other.ptr;
|
||||
this->ref = other.ref;
|
||||
other.ref = 0;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void userdata::add()
|
||||
{
|
||||
game::hks::HksObject value{};
|
||||
value.v.ptr = this->ptr;
|
||||
value.t = game::hks::TUSERDATA;
|
||||
|
||||
const auto state = *game::hks::lua_state;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
push_value(value);
|
||||
|
||||
this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000);
|
||||
}
|
||||
|
||||
void userdata::release()
|
||||
{
|
||||
if (this->ref)
|
||||
{
|
||||
game::hks::hksi_luaL_unref(*game::hks::lua_state, -10000, this->ref);
|
||||
}
|
||||
}
|
||||
|
||||
void userdata::set(const script_value& key, const script_value& value) const
|
||||
@ -41,11 +106,78 @@ namespace ui_scripting
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
this->ptr = game::hks::Hashtable_Create(state, 0, 0);
|
||||
this->add();
|
||||
}
|
||||
|
||||
table::table(game::hks::HashTable* ptr_)
|
||||
: ptr(ptr_)
|
||||
{
|
||||
this->add();
|
||||
}
|
||||
|
||||
table::table(const table& other)
|
||||
{
|
||||
this->operator=(other);
|
||||
}
|
||||
|
||||
table::table(table&& other) noexcept
|
||||
{
|
||||
this->ptr = other.ptr;
|
||||
this->ref = other.ref;
|
||||
other.ref = 0;
|
||||
}
|
||||
|
||||
table::~table()
|
||||
{
|
||||
this->release();
|
||||
}
|
||||
|
||||
table& table::operator=(const table& other)
|
||||
{
|
||||
if (&other != this)
|
||||
{
|
||||
this->release();
|
||||
this->ptr = other.ptr;
|
||||
this->ref = other.ref;
|
||||
this->add();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
table& table::operator=(table&& other) noexcept
|
||||
{
|
||||
if (&other != this)
|
||||
{
|
||||
this->release();
|
||||
this->ptr = other.ptr;
|
||||
this->ref = other.ref;
|
||||
other.ref = 0;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void table::add()
|
||||
{
|
||||
game::hks::HksObject value{};
|
||||
value.v.table = this->ptr;
|
||||
value.t = game::hks::TTABLE;
|
||||
|
||||
const auto state = *game::hks::lua_state;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
push_value(value);
|
||||
|
||||
this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000);
|
||||
}
|
||||
|
||||
void table::release()
|
||||
{
|
||||
if (this->ref)
|
||||
{
|
||||
game::hks::hksi_luaL_unref(*game::hks::lua_state, -10000, this->ref);
|
||||
}
|
||||
}
|
||||
|
||||
void table::set(const script_value& key, const script_value& value) const
|
||||
@ -69,9 +201,9 @@ namespace ui_scripting
|
||||
this->add();
|
||||
}
|
||||
|
||||
function::function(const function& other) : function(other.ptr, other.type)
|
||||
function::function(const function& other)
|
||||
{
|
||||
this->ref = other.ref;
|
||||
this->operator=(other);
|
||||
}
|
||||
|
||||
function::function(function&& other) noexcept
|
||||
@ -121,7 +253,9 @@ namespace ui_scripting
|
||||
value.v.cClosure = this->ptr;
|
||||
value.t = this->type;
|
||||
|
||||
stack_isolation _;
|
||||
const auto state = *game::hks::lua_state;
|
||||
state->m_apistack.top = state->m_apistack.base;
|
||||
|
||||
push_value(value);
|
||||
|
||||
this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000);
|
||||
|
@ -16,10 +16,24 @@ namespace ui_scripting
|
||||
public:
|
||||
userdata(void*);
|
||||
|
||||
userdata(const userdata& other);
|
||||
userdata(userdata&& other) noexcept;
|
||||
|
||||
~userdata();
|
||||
|
||||
userdata& operator=(const userdata& other);
|
||||
userdata& operator=(userdata&& other) noexcept;
|
||||
|
||||
script_value get(const script_value& key) const;
|
||||
void set(const script_value& key, const script_value& value) const;
|
||||
|
||||
void* ptr;
|
||||
|
||||
private:
|
||||
void add();
|
||||
void release();
|
||||
|
||||
int ref{};
|
||||
};
|
||||
|
||||
class table
|
||||
@ -28,10 +42,24 @@ namespace ui_scripting
|
||||
table();
|
||||
table(game::hks::HashTable* ptr_);
|
||||
|
||||
table(const table& other);
|
||||
table(table&& other) noexcept;
|
||||
|
||||
~table();
|
||||
|
||||
table& operator=(const table& other);
|
||||
table& operator=(table&& other) noexcept;
|
||||
|
||||
script_value get(const script_value& key) const;
|
||||
void set(const script_value& key, const script_value& value) const;
|
||||
|
||||
game::hks::HashTable* ptr;
|
||||
|
||||
private:
|
||||
void add();
|
||||
void release();
|
||||
|
||||
int ref{};
|
||||
};
|
||||
|
||||
class function
|
||||
@ -56,6 +84,6 @@ namespace ui_scripting
|
||||
void add();
|
||||
void release();
|
||||
|
||||
int ref;
|
||||
int ref{};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user