add mysql & http funcs

This commit is contained in:
alice
2026-07-28 23:44:07 +02:00
parent befebc4b6e
commit 0b79c0c114
43 changed files with 3023 additions and 146 deletions
+2
View File
@@ -76,6 +76,8 @@ namespace scripting
{
return {this->id_, this->get_value_id(key.as<S>())};
}
throw std::runtime_error("invalid key type");
}
private:
+1
View File
@@ -2,6 +2,7 @@
#include "game/game.hpp"
#include "entity.hpp"
#include "array.hpp"
#include "object.hpp"
#include "function.hpp"
#include "script_value.hpp"
+89
View File
@@ -0,0 +1,89 @@
#include <stdinc.hpp>
#include "object.hpp"
#include "script_value.hpp"
#include "execution.hpp"
namespace scripting
{
object::object(const unsigned int id)
: id_(id)
{
this->add();
}
object::object(const object& other)
: object(other.id_)
{
}
object::object(object&& other) noexcept
{
this->id_ = other.id_;
other.id_ = 0;
}
object::object()
{
this->id_ = make_object();
}
object::~object()
{
this->release();
}
object& object::operator=(const object& other)
{
if (&other != this)
{
this->release();
this->id_ = other.id_;
this->add();
}
return *this;
}
object& object::operator=(object&& other) noexcept
{
if (&other != this)
{
this->release();
this->id_ = other.id_;
other.id_ = 0;
}
return *this;
}
void object::add() const
{
if (this->id_)
{
game::AddRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->id_)});
}
}
void object::release() const
{
if (this->id_)
{
game::RemoveRefToValue(game::SCRIPT_OBJECT, {static_cast<int>(this->id_)});
}
}
unsigned int object::size() const
{
return game::Scr_GetSelf(this->id_);
}
unsigned int object::get_entity_id() const
{
return this->id_;
}
entity object::get_raw() const
{
return entity(this->id_);
}
}
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include "game/game.hpp"
#include "script_value.hpp"
namespace scripting
{
class object final
{
public:
object();
object(const unsigned int);
object(const object& other);
object(object&& other) noexcept;
~object();
object& operator=(const object& other);
object& operator=(object&& other) noexcept;
unsigned int size() const;
unsigned int get_entity_id() const;
entity get_raw() const;
private:
void add() const;
void release() const;
unsigned int id_;
};
}
+86
View File
@@ -2,6 +2,7 @@
#include "script_value.hpp"
#include "entity.hpp"
#include "array.hpp"
#include "object.hpp"
#include "function.hpp"
namespace scripting
@@ -117,6 +118,15 @@ namespace scripting
this->value_ = variable;
}
script_value::script_value(const object& value)
{
game::VariableValue variable{};
variable.type = game::SCRIPT_OBJECT;
variable.u.pointerValue = value.get_entity_id();
this->value_ = variable;
}
script_value::script_value(const function& value)
{
game::VariableValue variable{};
@@ -142,6 +152,12 @@ namespace scripting
return this->is<int>();
}
template <>
bool script_value::is<unsigned short>() const
{
return this->is<int>();
}
template <>
bool script_value::is<bool>() const
{
@@ -160,6 +176,12 @@ namespace scripting
return this->get_raw().u.uintValue;
}
template <>
unsigned short script_value::get() const
{
return static_cast<unsigned short>(this->get_raw().u.uintValue);
}
template <>
bool script_value::get() const
{
@@ -262,6 +284,32 @@ namespace scripting
return array(this->get_raw().u.uintValue);
}
/***************************************************************
* Array
**************************************************************/
template <>
bool script_value::is<object>() const
{
if (this->get_raw().type != game::SCRIPT_OBJECT)
{
return false;
}
const auto id = this->get_raw().u.uintValue;
const auto type = game::scr_VarGlob->objectVariableValue[id].w.type;
return type == game::SCRIPT_STRUCT;
}
template <>
object script_value::get() const
{
return object(this->get_raw().u.uintValue);
}
/***************************************************************
* Struct
**************************************************************/
@@ -321,6 +369,44 @@ namespace scripting
return this->value_.get();
}
std::string script_value::to_string() const
{
if (this->is<int>())
{
return utils::string::va("%i", this->as<int>());
}
if (this->is<float>())
{
return utils::string::va("%f", this->as<float>());
}
if (this->is<std::string>())
{
return this->as<std::string>();
}
if (this->is<vector>())
{
const auto vec = this->as<vector>();
return utils::string::va("(%g, %g, %g)",
vec.get_x(),
vec.get_y(),
vec.get_z()
);
}
if (this->is<function>())
{
const auto func = this->as<function>();
const auto pos = func.get_pos();
return utils::string::va("[[ function: %p ]]", pos);
}
return this->type_name();
}
value_wrap::value_wrap(const scripting::script_value& value, const std::uint32_t argument_index)
: value_(value)
, argument_index_(argument_index)
+15
View File
@@ -7,6 +7,7 @@ namespace scripting
{
class entity;
class array;
class object;
class function;
class value_wrap;
@@ -82,6 +83,11 @@ namespace scripting
return "array";
}
if (info == typeid(object))
{
return "object";
}
if (info == typeid(function))
{
return "function";
@@ -121,6 +127,8 @@ namespace scripting
script_value(const array& value);
script_value(const object& value);
script_value(const function& value);
template <typename T>
@@ -153,8 +161,15 @@ namespace scripting
return reinterpret_cast<T*>(value);
}
std::string type_name() const
{
return get_typename(this->get_raw());
}
const game::VariableValue& get_raw() const;
std::string to_string() const;
variable_value value_{};
private:
template <typename T>