feat: add GetChar utils function

This commit is contained in:
FutureRave 2023-03-06 13:29:18 +00:00
parent 1f13b263ba
commit 4371a9843b
No known key found for this signature in database
GPG Key ID: 22F9079C86CFAB31

37
src/module/gsc/string.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <std_include.hpp>
#include <loader/module_loader.hpp>
#include "game/game.hpp"
#include "script_error.hpp"
#include "script_extension.hpp"
namespace gsc
{
class string final : public module
{
public:
void post_load() override
{
register_function("getchar", []
{
const auto* str = game::native::Scr_GetString(0);
const auto index = scr_get_int(1);
if (!str)
{
scr_error("^GetChar: Illegal parameter!\n");
return;
}
if (static_cast<std::size_t>(index) >= std::strlen(str))
{
scr_error("GetChar: char index is out of bounds");
}
game::native::Scr_AddInt(str[index]);
});
}
};
}
REGISTER_MODULE(gsc::string)