1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 00:42:45 +01:00

Codechange: use std::string_view for sq_pushstring

This commit is contained in:
Rubidium
2025-05-03 13:19:53 +02:00
committed by rubidium42
parent 3020e615a9
commit ec79ceb2be
17 changed files with 52 additions and 55 deletions

View File

@@ -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))) {