feat: add GetChar utils function
This commit is contained in:
parent
1f13b263ba
commit
4371a9843b
37
src/module/gsc/string.cpp
Normal file
37
src/module/gsc/string.cpp
Normal 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)
|
Loading…
Reference in New Issue
Block a user