#include "commons.hpp" #include "src/Prototype.hpp" extern "C" void lib_cast(grino::Loader& loader) { grino::Loc loc {"core/casts"}; loader.add_native("stoi", [loc](auto args){ std::string value = args[0]->as_string(); return grino::Value::make_int(loc, std::stoi(value)); }, std::make_shared(std::vector{ grino::TypeSlot {grino::HINT_CAT_PARAM, grino::TYPE_STRING}, grino::TypeSlot {grino::HINT_CAT_RETURN, grino::TYPE_INT} })); loader.add_native("itos", [loc](auto args){ int value = args[0]->as_int(); return grino::Value::make_string(loc, std::to_string(value)); }, std::make_shared(std::vector{ grino::TypeSlot {grino::HINT_CAT_PARAM, grino::TYPE_INT}, grino::TypeSlot {grino::HINT_CAT_RETURN, grino::TYPE_STRING} })); loader.add_native("stof", [loc](auto args){ std::string value = args[0]->as_string(); return grino::Value::make_int(loc, std::stof(value)); }, std::make_shared(std::vector{ grino::TypeSlot {grino::HINT_CAT_PARAM, grino::TYPE_STRING}, grino::TypeSlot {grino::HINT_CAT_RETURN, grino::TYPE_FLOAT} })); loader.add_native("ftos", [loc](auto args){ float value = args[0]->as_float(); return grino::Value::make_string(loc, std::to_string(value)); }, std::make_shared(std::vector{ grino::TypeSlot {grino::HINT_CAT_PARAM, grino::TYPE_FLOAT}, grino::TypeSlot {grino::HINT_CAT_RETURN, grino::TYPE_STRING} })); }