mirror of https://github.com/OpenTTD/OpenTTD
(svn r26771) -Cleanup: remove OTTD2SQ and SQ2OTTD
parent
3f9525ff0e
commit
7c4e9dd71d
|
@ -361,7 +361,7 @@ void RegisterGameTranslation(Squirrel *engine)
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (const char * const *p = _current_data->string_names.Begin(); p != _current_data->string_names.End(); p++, idx++) {
|
for (const char * const *p = _current_data->string_names.Begin(); p != _current_data->string_names.End(); p++, idx++) {
|
||||||
sq_pushstring(vm, OTTD2SQ(*p), -1);
|
sq_pushstring(vm, *p, -1);
|
||||||
sq_pushinteger(vm, idx);
|
sq_pushinteger(vm, idx);
|
||||||
sq_rawset(vm, -3);
|
sq_rawset(vm, -3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
case OT_STRING: {
|
case OT_STRING: {
|
||||||
const SQChar *res;
|
const SQChar *buf;
|
||||||
sq_getstring(vm, index, &res);
|
sq_getstring(vm, index, &buf);
|
||||||
|
|
||||||
/* @bug if a string longer than 512 characters is given to SQ2OTTD, the
|
|
||||||
* internal buffer overflows. */
|
|
||||||
const char *buf = SQ2OTTD(res);
|
|
||||||
size_t len = strlen(buf) + 1;
|
size_t len = strlen(buf) + 1;
|
||||||
if (len >= 255) {
|
if (len >= 255) {
|
||||||
ScriptLog::Error("Maximum string length is 254 chars. No data sent.");
|
ScriptLog::Error("Maximum string length is 254 chars. No data sent.");
|
||||||
|
|
|
@ -122,7 +122,7 @@ ScriptController::~ScriptController()
|
||||||
if (lib == NULL) {
|
if (lib == NULL) {
|
||||||
char error[1024];
|
char error[1024];
|
||||||
seprintf(error, lastof(error), "couldn't find library '%s' with version %d", library, version);
|
seprintf(error, lastof(error), "couldn't find library '%s' with version %d", library, version);
|
||||||
throw sq_throwerror(vm, OTTD2SQ(error));
|
throw sq_throwerror(vm, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the current table/class we belong to */
|
/* Get the current table/class we belong to */
|
||||||
|
@ -142,13 +142,13 @@ ScriptController::~ScriptController()
|
||||||
|
|
||||||
/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
|
/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
|
||||||
sq_pushroottable(vm);
|
sq_pushroottable(vm);
|
||||||
sq_pushstring(vm, OTTD2SQ(fake_class), -1);
|
sq_pushstring(vm, fake_class, -1);
|
||||||
sq_newclass(vm, SQFalse);
|
sq_newclass(vm, SQFalse);
|
||||||
/* Load the library */
|
/* Load the library */
|
||||||
if (!engine->LoadScript(vm, lib->GetMainScript(), false)) {
|
if (!engine->LoadScript(vm, lib->GetMainScript(), false)) {
|
||||||
char error[1024];
|
char error[1024];
|
||||||
seprintf(error, lastof(error), "there was a compile error when importing '%s' version %d", library, version);
|
seprintf(error, lastof(error), "there was a compile error when importing '%s' version %d", library, version);
|
||||||
throw sq_throwerror(vm, OTTD2SQ(error));
|
throw sq_throwerror(vm, error);
|
||||||
}
|
}
|
||||||
/* Create the fake class */
|
/* Create the fake class */
|
||||||
sq_newslot(vm, -3, SQFalse);
|
sq_newslot(vm, -3, SQFalse);
|
||||||
|
@ -159,15 +159,15 @@ ScriptController::~ScriptController()
|
||||||
|
|
||||||
/* Find the real class inside the fake class (like 'sets.Vector') */
|
/* Find the real class inside the fake class (like 'sets.Vector') */
|
||||||
sq_pushroottable(vm);
|
sq_pushroottable(vm);
|
||||||
sq_pushstring(vm, OTTD2SQ(fake_class), -1);
|
sq_pushstring(vm, fake_class, -1);
|
||||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||||
throw sq_throwerror(vm, _SC("internal error assigning library class"));
|
throw sq_throwerror(vm, _SC("internal error assigning library class"));
|
||||||
}
|
}
|
||||||
sq_pushstring(vm, OTTD2SQ(lib->GetInstanceName()), -1);
|
sq_pushstring(vm, lib->GetInstanceName(), -1);
|
||||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||||
char error[1024];
|
char error[1024];
|
||||||
seprintf(error, lastof(error), "unable to find class '%s' in the library '%s' version %d", lib->GetInstanceName(), library, version);
|
seprintf(error, lastof(error), "unable to find class '%s' in the library '%s' version %d", lib->GetInstanceName(), library, version);
|
||||||
throw sq_throwerror(vm, OTTD2SQ(error));
|
throw sq_throwerror(vm, error);
|
||||||
}
|
}
|
||||||
HSQOBJECT obj;
|
HSQOBJECT obj;
|
||||||
sq_getstackobj(vm, -1, &obj);
|
sq_getstackobj(vm, -1, &obj);
|
||||||
|
@ -177,7 +177,7 @@ ScriptController::~ScriptController()
|
||||||
|
|
||||||
/* Now link the name the user wanted to our 'fake' class */
|
/* Now link the name the user wanted to our 'fake' class */
|
||||||
sq_pushobject(vm, parent);
|
sq_pushobject(vm, parent);
|
||||||
sq_pushstring(vm, OTTD2SQ(class_name), -1);
|
sq_pushstring(vm, class_name, -1);
|
||||||
sq_pushobject(vm, obj);
|
sq_pushobject(vm, obj);
|
||||||
sq_newclass(vm, SQTrue);
|
sq_newclass(vm, SQTrue);
|
||||||
sq_newslot(vm, -3, SQFalse);
|
sq_newslot(vm, -3, SQFalse);
|
||||||
|
|
|
@ -171,7 +171,7 @@ char *ScriptEventAdminPort::ReadString(HSQUIRRELVM vm, char *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
sq_pushstring(vm, OTTD2SQ(value), -1);
|
sq_pushstring(vm, value, -1);
|
||||||
*p++ = '"';
|
*p++ = '"';
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|
|
@ -83,7 +83,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
||||||
const SQChar *value;
|
const SQChar *value;
|
||||||
sq_getstring(vm, -1, &value);
|
sq_getstring(vm, -1, &value);
|
||||||
|
|
||||||
this->params[parameter] = stredup(SQ2OTTD(value));
|
this->params[parameter] = stredup(value);
|
||||||
ValidateString(this->params[parameter]);
|
ValidateString(this->params[parameter]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -157,9 +157,8 @@ SQInteger ScriptText::_set(HSQUIRRELVM vm)
|
||||||
int32 k;
|
int32 k;
|
||||||
|
|
||||||
if (sq_gettype(vm, 2) == OT_STRING) {
|
if (sq_gettype(vm, 2) == OT_STRING) {
|
||||||
const SQChar *key;
|
const SQChar *key_string;
|
||||||
sq_getstring(vm, 2, &key);
|
sq_getstring(vm, 2, &key_string);
|
||||||
const char *key_string = SQ2OTTD(key);
|
|
||||||
ValidateString(key_string);
|
ValidateString(key_string);
|
||||||
|
|
||||||
if (strncmp(key_string, "param_", 6) != 0 || strlen(key_string) > 8) return SQ_ERROR;
|
if (strncmp(key_string, "param_", 6) != 0 || strlen(key_string) > 8) return SQ_ERROR;
|
||||||
|
|
|
@ -125,15 +125,14 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||||
/* Read the table, and find all properties we care about */
|
/* Read the table, and find all properties we care about */
|
||||||
sq_pushnull(vm);
|
sq_pushnull(vm);
|
||||||
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
||||||
const SQChar *sqkey;
|
const SQChar *key;
|
||||||
if (SQ_FAILED(sq_getstring(vm, -2, &sqkey))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getstring(vm, -2, &key))) return SQ_ERROR;
|
||||||
const char *key = SQ2OTTD(sqkey);
|
|
||||||
ValidateString(key);
|
ValidateString(key);
|
||||||
|
|
||||||
if (strcmp(key, "name") == 0) {
|
if (strcmp(key, "name") == 0) {
|
||||||
const SQChar *sqvalue;
|
const SQChar *sqvalue;
|
||||||
if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) return SQ_ERROR;
|
||||||
char *name = stredup(SQ2OTTD(sqvalue));
|
char *name = stredup(sqvalue);
|
||||||
char *s;
|
char *s;
|
||||||
ValidateString(name);
|
ValidateString(name);
|
||||||
|
|
||||||
|
@ -146,7 +145,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||||
} else if (strcmp(key, "description") == 0) {
|
} else if (strcmp(key, "description") == 0) {
|
||||||
const SQChar *sqdescription;
|
const SQChar *sqdescription;
|
||||||
if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription))) return SQ_ERROR;
|
||||||
config.description = stredup(SQ2OTTD(sqdescription));
|
config.description = stredup(sqdescription);
|
||||||
ValidateString(config.description);
|
ValidateString(config.description);
|
||||||
items |= 0x002;
|
items |= 0x002;
|
||||||
} else if (strcmp(key, "min_value") == 0) {
|
} else if (strcmp(key, "min_value") == 0) {
|
||||||
|
@ -230,9 +229,8 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
|
||||||
|
|
||||||
SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
|
SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
const SQChar *sq_setting_name;
|
const SQChar *setting_name;
|
||||||
if (SQ_FAILED(sq_getstring(vm, -2, &sq_setting_name))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getstring(vm, -2, &setting_name))) return SQ_ERROR;
|
||||||
const char *setting_name = SQ2OTTD(sq_setting_name);
|
|
||||||
ValidateString(setting_name);
|
ValidateString(setting_name);
|
||||||
|
|
||||||
ScriptConfigItem *config = NULL;
|
ScriptConfigItem *config = NULL;
|
||||||
|
@ -253,15 +251,13 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
|
||||||
/* Read the table and find all labels */
|
/* Read the table and find all labels */
|
||||||
sq_pushnull(vm);
|
sq_pushnull(vm);
|
||||||
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
|
||||||
const SQChar *sq_key;
|
const SQChar *key_string;
|
||||||
const SQChar *sq_label;
|
const SQChar *label;
|
||||||
if (SQ_FAILED(sq_getstring(vm, -2, &sq_key))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getstring(vm, -2, &key_string))) return SQ_ERROR;
|
||||||
if (SQ_FAILED(sq_getstring(vm, -1, &sq_label))) return SQ_ERROR;
|
if (SQ_FAILED(sq_getstring(vm, -1, &label))) return SQ_ERROR;
|
||||||
/* Because squirrel doesn't support identifiers starting with a digit,
|
/* Because squirrel doesn't support identifiers starting with a digit,
|
||||||
* we skip the first character. */
|
* we skip the first character. */
|
||||||
const char *key_string = SQ2OTTD(sq_key);
|
|
||||||
int key = atoi(key_string + 1);
|
int key = atoi(key_string + 1);
|
||||||
const char *label = SQ2OTTD(sq_label);
|
|
||||||
ValidateString(label);
|
ValidateString(label);
|
||||||
|
|
||||||
/* !Contains() prevents stredup from leaking. */
|
/* !Contains() prevents stredup from leaking. */
|
||||||
|
|
|
@ -41,7 +41,7 @@ void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir)
|
||||||
dp += seprintf(dp, lastof(dummy_script), "function CreateInstance() { return \"Dummy%s\"; }\n", type);
|
dp += seprintf(dp, lastof(dummy_script), "function CreateInstance() { return \"Dummy%s\"; }\n", type);
|
||||||
dp += seprintf(dp, lastof(dummy_script), "} RegisterDummy%s(Dummy%s());\n", type, type);
|
dp += seprintf(dp, lastof(dummy_script), "} RegisterDummy%s(Dummy%s());\n", type, type);
|
||||||
|
|
||||||
const SQChar *sq_dummy_script = OTTD2SQ(dummy_script);
|
const SQChar *sq_dummy_script = dummy_script;
|
||||||
|
|
||||||
sq_pushroottable(vm);
|
sq_pushroottable(vm);
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type)
|
||||||
/* 3) We translate the error message in the character format that Squirrel wants.
|
/* 3) We translate the error message in the character format that Squirrel wants.
|
||||||
* We can use the fact that the wchar string printing also uses %s to print
|
* We can use the fact that the wchar string printing also uses %s to print
|
||||||
* old style char strings, which is what was generated during the script generation. */
|
* old style char strings, which is what was generated during the script generation. */
|
||||||
const SQChar *sq_dummy_script = OTTD2SQ(dummy_script);
|
const SQChar *sq_dummy_script = dummy_script;
|
||||||
|
|
||||||
/* And finally we load and run the script */
|
/* And finally we load and run the script */
|
||||||
sq_pushroottable(vm);
|
sq_pushroottable(vm);
|
||||||
|
|
|
@ -46,7 +46,7 @@ ScriptStorage::~ScriptStorage()
|
||||||
static void PrintFunc(bool error_msg, const SQChar *message)
|
static void PrintFunc(bool error_msg, const SQChar *message)
|
||||||
{
|
{
|
||||||
/* Convert to OpenTTD internal capable string */
|
/* Convert to OpenTTD internal capable string */
|
||||||
ScriptController::Print(error_msg, SQ2OTTD(message));
|
ScriptController::Print(error_msg, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptInstance::ScriptInstance(const char *APIName) :
|
ScriptInstance::ScriptInstance(const char *APIName) :
|
||||||
|
@ -367,11 +367,8 @@ static const SaveLoad _script_byte[] = {
|
||||||
_script_sl_byte = SQSL_STRING;
|
_script_sl_byte = SQSL_STRING;
|
||||||
SlObject(NULL, _script_byte);
|
SlObject(NULL, _script_byte);
|
||||||
}
|
}
|
||||||
const SQChar *res;
|
const SQChar *buf;
|
||||||
sq_getstring(vm, index, &res);
|
sq_getstring(vm, index, &buf);
|
||||||
/* @bug if a string longer than 512 characters is given to SQ2OTTD, the
|
|
||||||
* internal buffer overflows. */
|
|
||||||
const char *buf = SQ2OTTD(res);
|
|
||||||
size_t len = strlen(buf) + 1;
|
size_t len = strlen(buf) + 1;
|
||||||
if (len >= 255) {
|
if (len >= 255) {
|
||||||
ScriptLog::Error("Maximum string length is 254 chars. No data saved.");
|
ScriptLog::Error("Maximum string length is 254 chars. No data saved.");
|
||||||
|
@ -569,7 +566,7 @@ bool ScriptInstance::IsPaused()
|
||||||
SlObject(NULL, _script_byte);
|
SlObject(NULL, _script_byte);
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
SlArray(buf, _script_sl_byte, SLE_CHAR);
|
SlArray(buf, _script_sl_byte, SLE_CHAR);
|
||||||
if (vm != NULL) sq_pushstring(vm, OTTD2SQ(buf), -1);
|
if (vm != NULL) sq_pushstring(vm, buf, -1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,7 +655,7 @@ bool ScriptInstance::CallLoad()
|
||||||
/* Go to the instance-root */
|
/* Go to the instance-root */
|
||||||
sq_pushobject(vm, *this->instance);
|
sq_pushobject(vm, *this->instance);
|
||||||
/* Find the function-name inside the script */
|
/* Find the function-name inside the script */
|
||||||
sq_pushstring(vm, OTTD2SQ("Load"), -1);
|
sq_pushstring(vm, "Load", -1);
|
||||||
/* Change the "Load" string in a function pointer */
|
/* Change the "Load" string in a function pointer */
|
||||||
sq_get(vm, -2);
|
sq_get(vm, -2);
|
||||||
/* Push the main instance as "this" object */
|
/* Push the main instance as "this" object */
|
||||||
|
|
|
@ -38,7 +38,7 @@ void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *so
|
||||||
engine->crashed = true;
|
engine->crashed = true;
|
||||||
SQPrintFunc *func = engine->print_func;
|
SQPrintFunc *func = engine->print_func;
|
||||||
if (func == NULL) {
|
if (func == NULL) {
|
||||||
DEBUG(misc, 0, "[Squirrel] Compile error: %s", SQ2OTTD(buf));
|
DEBUG(misc, 0, "[Squirrel] Compile error: %s", buf);
|
||||||
} else {
|
} else {
|
||||||
(*func)(true, buf);
|
(*func)(true, buf);
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ void Squirrel::PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
|
||||||
|
|
||||||
void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam, const char *params, void *userdata, int size)
|
void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam, const char *params, void *userdata, int size)
|
||||||
{
|
{
|
||||||
sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
|
sq_pushstring(this->vm, method_name, -1);
|
||||||
|
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
void *ptr = sq_newuserdata(vm, size);
|
void *ptr = sq_newuserdata(vm, size);
|
||||||
|
@ -129,21 +129,21 @@ void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam,
|
||||||
}
|
}
|
||||||
|
|
||||||
sq_newclosure(this->vm, proc, size != 0 ? 1 : 0);
|
sq_newclosure(this->vm, proc, size != 0 ? 1 : 0);
|
||||||
if (nparam != 0) sq_setparamscheck(this->vm, nparam, OTTD2SQ(params));
|
if (nparam != 0) sq_setparamscheck(this->vm, nparam, params);
|
||||||
sq_setnativeclosurename(this->vm, -1, OTTD2SQ(method_name));
|
sq_setnativeclosurename(this->vm, -1, method_name);
|
||||||
sq_newslot(this->vm, -3, SQFalse);
|
sq_newslot(this->vm, -3, SQFalse);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Squirrel::AddConst(const char *var_name, int value)
|
void Squirrel::AddConst(const char *var_name, int value)
|
||||||
{
|
{
|
||||||
sq_pushstring(this->vm, OTTD2SQ(var_name), -1);
|
sq_pushstring(this->vm, var_name, -1);
|
||||||
sq_pushinteger(this->vm, value);
|
sq_pushinteger(this->vm, value);
|
||||||
sq_newslot(this->vm, -3, SQTrue);
|
sq_newslot(this->vm, -3, SQTrue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Squirrel::AddConst(const char *var_name, bool value)
|
void Squirrel::AddConst(const char *var_name, bool value)
|
||||||
{
|
{
|
||||||
sq_pushstring(this->vm, OTTD2SQ(var_name), -1);
|
sq_pushstring(this->vm, var_name, -1);
|
||||||
sq_pushbool(this->vm, value);
|
sq_pushbool(this->vm, value);
|
||||||
sq_newslot(this->vm, -3, SQTrue);
|
sq_newslot(this->vm, -3, SQTrue);
|
||||||
}
|
}
|
||||||
|
@ -151,15 +151,15 @@ void Squirrel::AddConst(const char *var_name, bool value)
|
||||||
void Squirrel::AddClassBegin(const char *class_name)
|
void Squirrel::AddClassBegin(const char *class_name)
|
||||||
{
|
{
|
||||||
sq_pushroottable(this->vm);
|
sq_pushroottable(this->vm);
|
||||||
sq_pushstring(this->vm, OTTD2SQ(class_name), -1);
|
sq_pushstring(this->vm, class_name, -1);
|
||||||
sq_newclass(this->vm, SQFalse);
|
sq_newclass(this->vm, SQFalse);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Squirrel::AddClassBegin(const char *class_name, const char *parent_class)
|
void Squirrel::AddClassBegin(const char *class_name, const char *parent_class)
|
||||||
{
|
{
|
||||||
sq_pushroottable(this->vm);
|
sq_pushroottable(this->vm);
|
||||||
sq_pushstring(this->vm, OTTD2SQ(class_name), -1);
|
sq_pushstring(this->vm, class_name, -1);
|
||||||
sq_pushstring(this->vm, OTTD2SQ(parent_class), -1);
|
sq_pushstring(this->vm, parent_class, -1);
|
||||||
if (SQ_FAILED(sq_get(this->vm, -3))) {
|
if (SQ_FAILED(sq_get(this->vm, -3))) {
|
||||||
DEBUG(misc, 0, "[squirrel] Failed to initialize class '%s' based on parent class '%s'", class_name, parent_class);
|
DEBUG(misc, 0, "[squirrel] Failed to initialize class '%s' based on parent class '%s'", class_name, parent_class);
|
||||||
DEBUG(misc, 0, "[squirrel] Make sure that '%s' exists before trying to define '%s'", parent_class, class_name);
|
DEBUG(misc, 0, "[squirrel] Make sure that '%s' exists before trying to define '%s'", parent_class, class_name);
|
||||||
|
@ -181,7 +181,7 @@ bool Squirrel::MethodExists(HSQOBJECT instance, const char *method_name)
|
||||||
/* Go to the instance-root */
|
/* Go to the instance-root */
|
||||||
sq_pushobject(this->vm, instance);
|
sq_pushobject(this->vm, instance);
|
||||||
/* Find the function-name inside the script */
|
/* Find the function-name inside the script */
|
||||||
sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
|
sq_pushstring(this->vm, method_name, -1);
|
||||||
if (SQ_FAILED(sq_get(this->vm, -2))) {
|
if (SQ_FAILED(sq_get(this->vm, -2))) {
|
||||||
sq_settop(this->vm, top);
|
sq_settop(this->vm, top);
|
||||||
return false;
|
return false;
|
||||||
|
@ -232,7 +232,7 @@ bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT
|
||||||
/* Go to the instance-root */
|
/* Go to the instance-root */
|
||||||
sq_pushobject(this->vm, instance);
|
sq_pushobject(this->vm, instance);
|
||||||
/* Find the function-name inside the script */
|
/* Find the function-name inside the script */
|
||||||
sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
|
sq_pushstring(this->vm, method_name, -1);
|
||||||
if (SQ_FAILED(sq_get(this->vm, -2))) {
|
if (SQ_FAILED(sq_get(this->vm, -2))) {
|
||||||
DEBUG(misc, 0, "[squirrel] Could not find '%s' in the class", method_name);
|
DEBUG(misc, 0, "[squirrel] Could not find '%s' in the class", method_name);
|
||||||
sq_settop(this->vm, top);
|
sq_settop(this->vm, top);
|
||||||
|
@ -293,9 +293,9 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool
|
||||||
char *class_name2 = (char *)alloca(len);
|
char *class_name2 = (char *)alloca(len);
|
||||||
seprintf(class_name2, class_name2 + len - 1, "%s%s", engine->GetAPIName(), class_name);
|
seprintf(class_name2, class_name2 + len - 1, "%s%s", engine->GetAPIName(), class_name);
|
||||||
|
|
||||||
sq_pushstring(vm, OTTD2SQ(class_name2), -1);
|
sq_pushstring(vm, class_name2, -1);
|
||||||
} else {
|
} else {
|
||||||
sq_pushstring(vm, OTTD2SQ(class_name), -1);
|
sq_pushstring(vm, class_name, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SQ_FAILED(sq_get(vm, -2))) {
|
if (SQ_FAILED(sq_get(vm, -2))) {
|
||||||
|
@ -515,7 +515,7 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SQ_SUCCEEDED(sq_compile(vm, func, &f, OTTD2SQ(filename), printerror))) {
|
if (SQ_SUCCEEDED(sq_compile(vm, func, &f, filename, printerror))) {
|
||||||
FioFCloseFile(file);
|
FioFCloseFile(file);
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Convert a Squirrel-object to a string.
|
* Convert a Squirrel-object to a string.
|
||||||
*/
|
*/
|
||||||
static const char *ObjectToString(HSQOBJECT *ptr) { return SQ2OTTD(sq_objtostring(ptr)); }
|
static const char *ObjectToString(HSQOBJECT *ptr) { return sq_objtostring(ptr); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a Squirrel-object to an integer.
|
* Convert a Squirrel-object to an integer.
|
||||||
|
@ -230,7 +230,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Throw a Squirrel error that will be nicely displayed to the user.
|
* Throw a Squirrel error that will be nicely displayed to the user.
|
||||||
*/
|
*/
|
||||||
void ThrowError(const char *error) { sq_throwerror(this->vm, OTTD2SQ(error)); }
|
void ThrowError(const char *error) { sq_throwerror(this->vm, error); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release a SQ object.
|
* Release a SQ object.
|
||||||
|
|
|
@ -88,8 +88,8 @@ namespace SQConvert {
|
||||||
template <> inline int Return<int64> (HSQUIRRELVM vm, int64 res) { sq_pushinteger(vm, res); return 1; }
|
template <> inline int Return<int64> (HSQUIRRELVM vm, int64 res) { sq_pushinteger(vm, res); return 1; }
|
||||||
template <> inline int Return<Money> (HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, res); return 1; }
|
template <> inline int Return<Money> (HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, res); return 1; }
|
||||||
template <> inline int Return<bool> (HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; }
|
template <> inline int Return<bool> (HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; }
|
||||||
template <> inline int Return<char *> (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, OTTD2SQ(res), -1); free(res); } return 1; }
|
template <> inline int Return<char *> (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, res, -1); free(res); } return 1; }
|
||||||
template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, OTTD2SQ(res), -1); } return 1; }
|
template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, res, -1); } return 1; }
|
||||||
template <> inline int Return<void *> (HSQUIRRELVM vm, void *res) { sq_pushuserpointer(vm, res); return 1; }
|
template <> inline int Return<void *> (HSQUIRRELVM vm, void *res) { sq_pushuserpointer(vm, res); return 1; }
|
||||||
template <> inline int Return<HSQOBJECT> (HSQUIRRELVM vm, HSQOBJECT res) { sq_pushobject(vm, res); return 1; }
|
template <> inline int Return<HSQOBJECT> (HSQUIRRELVM vm, HSQOBJECT res) { sq_pushobject(vm, res); return 1; }
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ namespace SQConvert {
|
||||||
|
|
||||||
const SQChar *tmp;
|
const SQChar *tmp;
|
||||||
sq_getstring(vm, -1, &tmp);
|
sq_getstring(vm, -1, &tmp);
|
||||||
char *tmp_str = stredup(SQ2OTTD(tmp));
|
char *tmp_str = stredup(tmp);
|
||||||
sq_poptop(vm);
|
sq_poptop(vm);
|
||||||
*ptr->Append() = (void *)tmp_str;
|
*ptr->Append() = (void *)tmp_str;
|
||||||
str_validate(tmp_str, tmp_str + strlen(tmp_str));
|
str_validate(tmp_str, tmp_str + strlen(tmp_str));
|
||||||
|
@ -749,7 +749,7 @@ namespace SQConvert {
|
||||||
/* Protect against calls to a non-static method in a static way */
|
/* Protect against calls to a non-static method in a static way */
|
||||||
sq_pushroottable(vm);
|
sq_pushroottable(vm);
|
||||||
const char *className = GetClassName<Tcls, Ttype>();
|
const char *className = GetClassName<Tcls, Ttype>();
|
||||||
sq_pushstring(vm, OTTD2SQ(className), -1);
|
sq_pushstring(vm, className, -1);
|
||||||
sq_get(vm, -2);
|
sq_get(vm, -2);
|
||||||
sq_pushobject(vm, instance);
|
sq_pushobject(vm, instance);
|
||||||
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
|
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
|
||||||
|
@ -791,7 +791,7 @@ namespace SQConvert {
|
||||||
/* Protect against calls to a non-static method in a static way */
|
/* Protect against calls to a non-static method in a static way */
|
||||||
sq_pushroottable(vm);
|
sq_pushroottable(vm);
|
||||||
const char *className = GetClassName<Tcls, Ttype>();
|
const char *className = GetClassName<Tcls, Ttype>();
|
||||||
sq_pushstring(vm, OTTD2SQ(className), -1);
|
sq_pushstring(vm, className, -1);
|
||||||
sq_get(vm, -2);
|
sq_get(vm, -2);
|
||||||
sq_pushobject(vm, instance);
|
sq_pushobject(vm, instance);
|
||||||
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
|
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
|
||||||
|
|
|
@ -73,7 +73,7 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
|
||||||
real_filename = ReallocT(real_filename, scstrlen(real_filename) + scstrlen(filename) + 1);
|
real_filename = ReallocT(real_filename, scstrlen(real_filename) + scstrlen(filename) + 1);
|
||||||
scstrcat(real_filename, filename);
|
scstrcat(real_filename, filename);
|
||||||
/* Tars dislike opening files with '/' on Windows.. so convert it to '\\' ;) */
|
/* Tars dislike opening files with '/' on Windows.. so convert it to '\\' ;) */
|
||||||
char *filen = stredup(SQ2OTTD(real_filename));
|
char *filen = stredup(real_filename);
|
||||||
#if (PATHSEPCHAR != '/')
|
#if (PATHSEPCHAR != '/')
|
||||||
for (char *n = filen; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
|
for (char *n = filen; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -301,14 +301,10 @@
|
||||||
|
|
||||||
const char *FS2OTTD(const TCHAR *name);
|
const char *FS2OTTD(const TCHAR *name);
|
||||||
const TCHAR *OTTD2FS(const char *name, bool console_cp = false);
|
const TCHAR *OTTD2FS(const char *name, bool console_cp = false);
|
||||||
#define SQ2OTTD(name) (name)
|
|
||||||
#define OTTD2SQ(name) (name)
|
|
||||||
#else
|
#else
|
||||||
#define fopen(file, mode) fopen(OTTD2FS(file), mode)
|
#define fopen(file, mode) fopen(OTTD2FS(file), mode)
|
||||||
const char *FS2OTTD(const char *name);
|
const char *FS2OTTD(const char *name);
|
||||||
const char *OTTD2FS(const char *name);
|
const char *OTTD2FS(const char *name);
|
||||||
#define SQ2OTTD(name) (name)
|
|
||||||
#define OTTD2SQ(name) (name)
|
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
#endif /* STRGEN || SETTINGSGEN */
|
#endif /* STRGEN || SETTINGSGEN */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue