mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-17 01:12:39 +01:00
Codechange: use std::string_view for sq_pushstring
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "../script_controller.hpp"
|
||||
|
||||
template <> SQInteger PushClassName<ScriptController, ScriptType::AI>(HSQUIRRELVM vm) { sq_pushstring(vm, "AIController", -1); return 1; }
|
||||
template <> SQInteger PushClassName<ScriptController, ScriptType::AI>(HSQUIRRELVM vm) { sq_pushstring(vm, "AIController"); return 1; }
|
||||
|
||||
void SQAIController_Register(Squirrel &engine)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "../script_controller.hpp"
|
||||
|
||||
template <> SQInteger PushClassName<ScriptController, ScriptType::GS>(HSQUIRRELVM vm) { sq_pushstring(vm, "GSController", -1); return 1; }
|
||||
template <> SQInteger PushClassName<ScriptController, ScriptType::GS>(HSQUIRRELVM vm) { sq_pushstring(vm, "GSController"); return 1; }
|
||||
|
||||
void SQGSController_Register(Squirrel &engine)
|
||||
{
|
||||
|
||||
@@ -125,7 +125,7 @@ ScriptController::ScriptController(::CompanyID company) :
|
||||
|
||||
/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, fake_class, -1);
|
||||
sq_pushstring(vm, fake_class);
|
||||
sq_newclass(vm, SQFalse);
|
||||
/* Load the library */
|
||||
if (!engine->LoadScript(vm, lib->GetMainScript(), false)) {
|
||||
@@ -140,11 +140,11 @@ ScriptController::ScriptController(::CompanyID company) :
|
||||
|
||||
/* Find the real class inside the fake class (like 'sets.Vector') */
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, fake_class, -1);
|
||||
sq_pushstring(vm, fake_class);
|
||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||
throw sq_throwerror(vm, "internal error assigning library class");
|
||||
}
|
||||
sq_pushstring(vm, lib->GetInstanceName(), -1);
|
||||
sq_pushstring(vm, lib->GetInstanceName());
|
||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||
throw sq_throwerror(vm, fmt::format("unable to find class '{}' in the library '{}' version {}", lib->GetInstanceName(), library, version));
|
||||
}
|
||||
@@ -156,7 +156,7 @@ ScriptController::ScriptController(::CompanyID company) :
|
||||
|
||||
/* Now link the name the user wanted to our 'fake' class */
|
||||
sq_pushobject(vm, parent);
|
||||
sq_pushstring(vm, class_name, -1);
|
||||
sq_pushstring(vm, class_name);
|
||||
sq_pushobject(vm, obj);
|
||||
sq_newclass(vm, SQTrue);
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
|
||||
@@ -139,7 +139,7 @@ static bool ScriptEventAdminPortReadValue(HSQUIRRELVM vm, nlohmann::json &json)
|
||||
|
||||
case nlohmann::json::value_t::string: {
|
||||
auto value = json.get<std::string>();
|
||||
sq_pushstring(vm, value.data(), value.size());
|
||||
sq_pushstring(vm, value);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ static bool ScriptEventAdminPortReadValue(HSQUIRRELVM vm, nlohmann::json &json)
|
||||
sq_newtable(vm);
|
||||
|
||||
for (auto &[key, value] : json.items()) {
|
||||
sq_pushstring(vm, key.data(), key.size());
|
||||
sq_pushstring(vm, key);
|
||||
|
||||
if (!ScriptEventAdminPortReadValue(vm, value)) {
|
||||
return false;
|
||||
|
||||
@@ -84,7 +84,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
||||
|
||||
/* Validate if it is a GSText instance */
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "GSText", -1);
|
||||
sq_pushstring(vm, "GSText");
|
||||
sq_get(vm, -2);
|
||||
sq_pushobject(vm, instance);
|
||||
if (sq_instanceof(vm) != SQTrue) return SQ_ERROR;
|
||||
@@ -171,9 +171,9 @@ void ScriptText::SetPadParameterCount(HSQUIRRELVM vm)
|
||||
|
||||
SQInteger top = sq_gettop(vm);
|
||||
sq_pushroottable(vm);
|
||||
sq_pushstring(vm, "GSText", -1);
|
||||
sq_pushstring(vm, "GSText");
|
||||
if (!SQ_FAILED(sq_get(vm, -2))) {
|
||||
sq_pushstring(vm, "SCRIPT_TEXT_MAX_PARAMETERS", -1);
|
||||
sq_pushstring(vm, "SCRIPT_TEXT_MAX_PARAMETERS");
|
||||
if (!SQ_FAILED(sq_get(vm, -2))) {
|
||||
SQInteger value;
|
||||
if (!SQ_FAILED(sq_getinteger(vm, -1, &value))) {
|
||||
|
||||
@@ -649,7 +649,7 @@ bool ScriptInstance::IsPaused()
|
||||
ScriptData *data;
|
||||
|
||||
bool operator()(const SQInteger &value) { sq_pushinteger(this->vm, value); return true; }
|
||||
bool operator()(const std::string &value) { sq_pushstring(this->vm, value, -1); return true; }
|
||||
bool operator()(const std::string &value) { sq_pushstring(this->vm, value); return true; }
|
||||
bool operator()(const SQBool &value) { sq_pushbool(this->vm, value); return true; }
|
||||
bool operator()(const SQSaveLoadType &type)
|
||||
{
|
||||
@@ -778,7 +778,7 @@ bool ScriptInstance::CallLoad()
|
||||
/* Go to the instance-root */
|
||||
sq_pushobject(vm, *this->instance);
|
||||
/* Find the function-name inside the script */
|
||||
sq_pushstring(vm, "Load", -1);
|
||||
sq_pushstring(vm, "Load");
|
||||
/* Change the "Load" string in a function pointer */
|
||||
sq_get(vm, -2);
|
||||
/* Push the main instance as "this" object */
|
||||
|
||||
@@ -257,7 +257,7 @@ void Squirrel::AddMethod(std::string_view method_name, SQFUNCTION proc, std::str
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushstring(this->vm, method_name, -1);
|
||||
sq_pushstring(this->vm, method_name);
|
||||
|
||||
if (size != 0) {
|
||||
void *ptr = sq_newuserdata(vm, size);
|
||||
@@ -274,7 +274,7 @@ void Squirrel::AddConst(std::string_view var_name, int value)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushstring(this->vm, var_name, -1);
|
||||
sq_pushstring(this->vm, var_name);
|
||||
sq_pushinteger(this->vm, value);
|
||||
sq_newslot(this->vm, -3, SQTrue);
|
||||
}
|
||||
@@ -283,7 +283,7 @@ void Squirrel::AddConst(std::string_view var_name, bool value)
|
||||
{
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushstring(this->vm, var_name, -1);
|
||||
sq_pushstring(this->vm, var_name);
|
||||
sq_pushbool(this->vm, value);
|
||||
sq_newslot(this->vm, -3, SQTrue);
|
||||
}
|
||||
@@ -293,7 +293,7 @@ void Squirrel::AddClassBegin(std::string_view class_name)
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushroottable(this->vm);
|
||||
sq_pushstring(this->vm, class_name, -1);
|
||||
sq_pushstring(this->vm, class_name);
|
||||
sq_newclass(this->vm, SQFalse);
|
||||
}
|
||||
|
||||
@@ -302,8 +302,8 @@ void Squirrel::AddClassBegin(std::string_view class_name, std::string_view paren
|
||||
ScriptAllocatorScope alloc_scope(this);
|
||||
|
||||
sq_pushroottable(this->vm);
|
||||
sq_pushstring(this->vm, class_name, -1);
|
||||
sq_pushstring(this->vm, parent_class, -1);
|
||||
sq_pushstring(this->vm, class_name);
|
||||
sq_pushstring(this->vm, parent_class);
|
||||
if (SQ_FAILED(sq_get(this->vm, -3))) {
|
||||
Debug(misc, 0, "[squirrel] Failed to initialize class '{}' based on parent class '{}'", class_name, parent_class);
|
||||
Debug(misc, 0, "[squirrel] Make sure that '{}' exists before trying to define '{}'", parent_class, class_name);
|
||||
@@ -329,7 +329,7 @@ bool Squirrel::MethodExists(HSQOBJECT instance, std::string_view method_name)
|
||||
/* Go to the instance-root */
|
||||
sq_pushobject(this->vm, instance);
|
||||
/* Find the function-name inside the script */
|
||||
sq_pushstring(this->vm, method_name, -1);
|
||||
sq_pushstring(this->vm, method_name);
|
||||
if (SQ_FAILED(sq_get(this->vm, -2))) {
|
||||
sq_settop(this->vm, top);
|
||||
return false;
|
||||
@@ -388,7 +388,7 @@ bool Squirrel::CallMethod(HSQOBJECT instance, std::string_view method_name, HSQO
|
||||
/* Go to the instance-root */
|
||||
sq_pushobject(this->vm, instance);
|
||||
/* Find the function-name inside the script */
|
||||
sq_pushstring(this->vm, method_name, -1);
|
||||
sq_pushstring(this->vm, method_name);
|
||||
if (SQ_FAILED(sq_get(this->vm, -2))) {
|
||||
Debug(misc, 0, "[squirrel] Could not find '{}' in the class", method_name);
|
||||
sq_settop(this->vm, top);
|
||||
@@ -445,9 +445,9 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, std::string_view method_name,
|
||||
|
||||
if (prepend_API_name) {
|
||||
std::string prepended_class_name = fmt::format("{}{}", engine->GetAPIName(), class_name);
|
||||
sq_pushstring(vm, prepended_class_name, -1);
|
||||
sq_pushstring(vm, prepended_class_name);
|
||||
} else {
|
||||
sq_pushstring(vm, class_name, -1);
|
||||
sq_pushstring(vm, class_name);
|
||||
}
|
||||
|
||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace SQConvert {
|
||||
static inline int Set(HSQUIRRELVM vm, std::optional<std::string> res)
|
||||
{
|
||||
if (res.has_value()) {
|
||||
sq_pushstring(vm, res.value(), -1);
|
||||
sq_pushstring(vm, res.value());
|
||||
} else {
|
||||
sq_pushnull(vm);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user