Fix format

This commit is contained in:
fed 2023-02-28 18:24:31 +01:00
parent 2bdf83fe8b
commit d6714ab799
2 changed files with 373 additions and 373 deletions

View File

@ -5,341 +5,341 @@
namespace ui_scripting namespace ui_scripting
{ {
/*************************************************************** /***************************************************************
* Lightuserdata * Lightuserdata
**************************************************************/ **************************************************************/
lightuserdata::lightuserdata(void* ptr_) lightuserdata::lightuserdata(void* ptr_)
: ptr(ptr_) : ptr(ptr_)
{ {
} }
/*************************************************************** /***************************************************************
* Userdata * Userdata
**************************************************************/ **************************************************************/
userdata::userdata(void* ptr_) userdata::userdata(void* ptr_)
: ptr(ptr_) : ptr(ptr_)
{ {
this->add(); this->add();
} }
userdata::userdata(const userdata& other) userdata::userdata(const userdata& other)
{ {
this->operator=(other); this->operator=(other);
} }
userdata::userdata(userdata&& other) noexcept userdata::userdata(userdata&& other) noexcept
{ {
this->ptr = other.ptr; this->ptr = other.ptr;
this->ref = other.ref; this->ref = other.ref;
other.ref = 0; other.ref = 0;
} }
userdata::~userdata() userdata::~userdata()
{ {
this->release(); this->release();
} }
userdata& userdata::operator=(const userdata& other) userdata& userdata::operator=(const userdata& other)
{ {
if (&other != this) if (&other != this)
{ {
this->release(); this->release();
this->ptr = other.ptr; this->ptr = other.ptr;
this->ref = other.ref; this->ref = other.ref;
this->add(); this->add();
} }
return *this; return *this;
} }
userdata& userdata::operator=(userdata&& other) noexcept userdata& userdata::operator=(userdata&& other) noexcept
{ {
if (&other != this) if (&other != this)
{ {
this->release(); this->release();
this->ptr = other.ptr; this->ptr = other.ptr;
this->ref = other.ref; this->ref = other.ref;
other.ref = 0; other.ref = 0;
} }
return *this; return *this;
} }
void userdata::add() void userdata::add()
{ {
game::hks::HksObject value{}; game::hks::HksObject value{};
value.v.ptr = this->ptr; value.v.ptr = this->ptr;
value.t = game::hks::TUSERDATA; value.t = game::hks::TUSERDATA;
const auto state = *game::hks::lua_state; const auto state = *game::hks::lua_state;
const auto top = state->m_apistack.top; const auto top = state->m_apistack.top;
push_value(value); push_value(value);
this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000); this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000);
state->m_apistack.top = top; state->m_apistack.top = top;
} }
void userdata::release() void userdata::release()
{ {
if (this->ref) if (this->ref)
{ {
game::hks::hksi_luaL_unref(*game::hks::lua_state, -10000, 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 void userdata::set(const script_value& key, const script_value& value) const
{ {
set_field(*this, key, value); set_field(*this, key, value);
} }
script_value userdata::get(const script_value& key) const script_value userdata::get(const script_value& key) const
{ {
return get_field(*this, key); return get_field(*this, key);
} }
userdata_value userdata::operator[](const script_value& key) const userdata_value userdata::operator[](const script_value& key) const
{ {
return {*this, key}; return {*this, key};
} }
userdata_value::userdata_value(const userdata& table, const script_value& key) userdata_value::userdata_value(const userdata& table, const script_value& key)
: userdata_(table) : userdata_(table)
, key_(key) , key_(key)
{ {
this->value_ = this->userdata_.get(key).get_raw(); this->value_ = this->userdata_.get(key).get_raw();
} }
void userdata_value::operator=(const script_value& value) void userdata_value::operator=(const script_value& value)
{ {
this->userdata_.set(this->key_, value); this->userdata_.set(this->key_, value);
this->value_ = value.get_raw(); this->value_ = value.get_raw();
} }
bool userdata_value::operator==(const script_value& value) bool userdata_value::operator==(const script_value& value)
{ {
return this->userdata_.get(this->key_) == value; return this->userdata_.get(this->key_) == value;
} }
/*************************************************************** /***************************************************************
* Table * Table
**************************************************************/ **************************************************************/
table::table() table::table()
{ {
const auto state = *game::hks::lua_state; const auto state = *game::hks::lua_state;
this->ptr = game::hks::Hashtable_Create(state, 0, 0); this->ptr = game::hks::Hashtable_Create(state, 0, 0);
this->add(); this->add();
} }
table::table(game::hks::HashTable* ptr_) table::table(game::hks::HashTable* ptr_)
: ptr(ptr_) : ptr(ptr_)
{ {
this->add(); this->add();
} }
table::table(const table& other) table::table(const table& other)
{ {
this->operator=(other); this->operator=(other);
} }
table::table(table&& other) noexcept table::table(table&& other) noexcept
{ {
this->ptr = other.ptr; this->ptr = other.ptr;
this->ref = other.ref; this->ref = other.ref;
other.ref = 0; other.ref = 0;
} }
table::~table() table::~table()
{ {
this->release(); this->release();
} }
table& table::operator=(const table& other) table& table::operator=(const table& other)
{ {
if (&other != this) if (&other != this)
{ {
this->release(); this->release();
this->ptr = other.ptr; this->ptr = other.ptr;
this->ref = other.ref; this->ref = other.ref;
this->add(); this->add();
} }
return *this; return *this;
} }
table& table::operator=(table&& other) noexcept table& table::operator=(table&& other) noexcept
{ {
if (&other != this) if (&other != this)
{ {
this->release(); this->release();
this->ptr = other.ptr; this->ptr = other.ptr;
this->ref = other.ref; this->ref = other.ref;
other.ref = 0; other.ref = 0;
} }
return *this; return *this;
} }
void table::add() void table::add()
{ {
game::hks::HksObject value{}; game::hks::HksObject value{};
value.v.table = this->ptr; value.v.table = this->ptr;
value.t = game::hks::TTABLE; value.t = game::hks::TTABLE;
const auto state = *game::hks::lua_state; const auto state = *game::hks::lua_state;
const auto top = state->m_apistack.top; const auto top = state->m_apistack.top;
push_value(value); push_value(value);
this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000); this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000);
state->m_apistack.top = top; state->m_apistack.top = top;
} }
void table::release() void table::release()
{ {
if (this->ref) if (this->ref)
{ {
game::hks::hksi_luaL_unref(*game::hks::lua_state, -10000, 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 void table::set(const script_value& key, const script_value& value) const
{ {
set_field(*this, key, value); set_field(*this, key, value);
} }
table_value table::operator[](const script_value& key) const table_value table::operator[](const script_value& key) const
{ {
return {*this, key}; return {*this, key};
} }
script_value table::get(const script_value& key) const script_value table::get(const script_value& key) const
{ {
return get_field(*this, key); return get_field(*this, key);
} }
table_value::table_value(const table& table, const script_value& key) table_value::table_value(const table& table, const script_value& key)
: table_(table) : table_(table)
, key_(key) , key_(key)
{ {
this->value_ = this->table_.get(key).get_raw(); this->value_ = this->table_.get(key).get_raw();
} }
void table_value::operator=(const script_value& value) void table_value::operator=(const script_value& value)
{ {
this->table_.set(this->key_, value); this->table_.set(this->key_, value);
this->value_ = value.get_raw(); this->value_ = value.get_raw();
} }
void table_value::operator=(const table_value& value) void table_value::operator=(const table_value& value)
{ {
this->table_.set(this->key_, value); this->table_.set(this->key_, value);
this->value_ = value.get_raw(); this->value_ = value.get_raw();
} }
bool table_value::operator==(const script_value& value) bool table_value::operator==(const script_value& value)
{ {
return this->table_.get(this->key_) == value; return this->table_.get(this->key_) == value;
} }
bool table_value::operator==(const table_value& value) bool table_value::operator==(const table_value& value)
{ {
return this->table_.get(this->key_) == value; return this->table_.get(this->key_) == value;
} }
/*************************************************************** /***************************************************************
* Function * Function
**************************************************************/ **************************************************************/
function::function(game::hks::lua_function func) function::function(game::hks::lua_function func)
{ {
const auto state = *game::hks::lua_state; const auto state = *game::hks::lua_state;
this->ptr = game::hks::cclosure_Create(state, func, 0, 0, 0); this->ptr = game::hks::cclosure_Create(state, func, 0, 0, 0);
this->type = game::hks::HksObjectType::TCFUNCTION; this->type = game::hks::HksObjectType::TCFUNCTION;
this->add(); this->add();
} }
function::function(game::hks::cclosure* ptr_, game::hks::HksObjectType type_) function::function(game::hks::cclosure* ptr_, game::hks::HksObjectType type_)
: ptr(ptr_) : ptr(ptr_)
, type(type_) , type(type_)
{ {
this->add(); this->add();
} }
function::function(const function& other) function::function(const function& other)
{ {
this->operator=(other); this->operator=(other);
} }
function::function(function&& other) noexcept function::function(function&& other) noexcept
{ {
this->ptr = other.ptr; this->ptr = other.ptr;
this->type = other.type; this->type = other.type;
this->ref = other.ref; this->ref = other.ref;
other.ref = 0; other.ref = 0;
} }
function::~function() function::~function()
{ {
this->release(); this->release();
} }
function& function::operator=(const function& other) function& function::operator=(const function& other)
{ {
if (&other != this) if (&other != this)
{ {
this->release(); this->release();
this->ptr = other.ptr; this->ptr = other.ptr;
this->type = other.type; this->type = other.type;
this->ref = other.ref; this->ref = other.ref;
this->add(); this->add();
} }
return *this; return *this;
} }
function& function::operator=(function&& other) noexcept function& function::operator=(function&& other) noexcept
{ {
if (&other != this) if (&other != this)
{ {
this->release(); this->release();
this->ptr = other.ptr; this->ptr = other.ptr;
this->type = other.type; this->type = other.type;
this->ref = other.ref; this->ref = other.ref;
other.ref = 0; other.ref = 0;
} }
return *this; return *this;
} }
void function::add() void function::add()
{ {
game::hks::HksObject value{}; game::hks::HksObject value{};
value.v.cClosure = this->ptr; value.v.cClosure = this->ptr;
value.t = this->type; value.t = this->type;
const auto state = *game::hks::lua_state; const auto state = *game::hks::lua_state;
const auto top = state->m_apistack.top; const auto top = state->m_apistack.top;
push_value(value); push_value(value);
this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000); this->ref = game::hks::hksi_luaL_ref(*game::hks::lua_state, -10000);
state->m_apistack.top = top; state->m_apistack.top = top;
} }
void function::release() void function::release()
{ {
if (this->ref) if (this->ref)
{ {
game::hks::hksi_luaL_unref(*game::hks::lua_state, -10000, this->ref); game::hks::hksi_luaL_unref(*game::hks::lua_state, -10000, this->ref);
} }
} }
arguments function::call(const arguments& arguments) const arguments function::call(const arguments& arguments) const
{ {
return call_script_function(*this, arguments); return call_script_function(*this, arguments);
} }
} }

View File

@ -5,132 +5,132 @@
namespace ui_scripting namespace ui_scripting
{ {
class lightuserdata class lightuserdata
{ {
public: public:
lightuserdata(void*); lightuserdata(void*);
void* ptr; void* ptr;
}; };
class userdata_value; class userdata_value;
class userdata class userdata
{ {
public: public:
userdata(void*); userdata(void*);
userdata(const userdata& other); userdata(const userdata& other);
userdata(userdata&& other) noexcept; userdata(userdata&& other) noexcept;
~userdata(); ~userdata();
userdata& operator=(const userdata& other); userdata& operator=(const userdata& other);
userdata& operator=(userdata&& other) noexcept; userdata& operator=(userdata&& other) noexcept;
script_value get(const script_value& key) const; script_value get(const script_value& key) const;
void set(const script_value& key, const script_value& value) const; void set(const script_value& key, const script_value& value) const;
userdata_value operator[](const script_value& key) const; userdata_value operator[](const script_value& key) const;
void* ptr; void* ptr;
private: private:
void add(); void add();
void release(); void release();
int ref{}; int ref{};
}; };
class userdata_value : public script_value class userdata_value : public script_value
{ {
public: public:
userdata_value(const userdata& table, const script_value& key); userdata_value(const userdata& table, const script_value& key);
void operator=(const script_value& value); void operator=(const script_value& value);
bool operator==(const script_value& value); bool operator==(const script_value& value);
private: private:
userdata userdata_; userdata userdata_;
script_value key_; script_value key_;
}; };
class table_value; class table_value;
class table class table
{ {
public: public:
table(); table();
table(game::hks::HashTable* ptr_); table(game::hks::HashTable* ptr_);
table(const table& other); table(const table& other);
table(table&& other) noexcept; table(table&& other) noexcept;
~table(); ~table();
table& operator=(const table& other); table& operator=(const table& other);
table& operator=(table&& other) noexcept; table& operator=(table&& other) noexcept;
script_value get(const script_value& key) const; script_value get(const script_value& key) const;
void set(const script_value& key, const script_value& value) const; void set(const script_value& key, const script_value& value) const;
table_value operator[](const script_value& key) const; table_value operator[](const script_value& key) const;
game::hks::HashTable* ptr; game::hks::HashTable* ptr;
private: private:
void add(); void add();
void release(); void release();
int ref{}; int ref{};
}; };
class table_value : public script_value class table_value : public script_value
{ {
public: public:
table_value(const table& table, const script_value& key); table_value(const table& table, const script_value& key);
void operator=(const script_value& value); void operator=(const script_value& value);
void operator=(const table_value& value); void operator=(const table_value& value);
bool operator==(const script_value& value); bool operator==(const script_value& value);
bool operator==(const table_value& value); bool operator==(const table_value& value);
private: private:
table table_; table table_;
script_value key_; script_value key_;
}; };
class function class function
{ {
public: public:
function(game::hks::lua_function); function(game::hks::lua_function);
function(game::hks::cclosure*, game::hks::HksObjectType); function(game::hks::cclosure*, game::hks::HksObjectType);
template <typename F> template <typename F>
function(F f) function(F f)
{ {
this->ptr = ui_scripting::convert_function(f); this->ptr = ui_scripting::convert_function(f);
this->type = game::hks::TCFUNCTION; this->type = game::hks::TCFUNCTION;
} }
function(const function& other); function(const function& other);
function(function&& other) noexcept; function(function&& other) noexcept;
~function(); ~function();
function& operator=(const function& other); function& operator=(const function& other);
function& operator=(function&& other) noexcept; function& operator=(function&& other) noexcept;
arguments call(const arguments& arguments) const; arguments call(const arguments& arguments) const;
template<class ...T> template<class ...T>
arguments operator()(T... arguments) const arguments operator()(T... arguments) const
{ {
return this->call({arguments...}); return this->call({arguments...});
} }
game::hks::cclosure* ptr; game::hks::cclosure* ptr;
game::hks::HksObjectType type; game::hks::HksObjectType type;
private: private:
void add(); void add();
void release(); void release();
int ref{}; int ref{};
}; };
} }