mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use string/fmt instead of printf for Squirrel's Raise_Error
parent
8b93e45e22
commit
5733142b0d
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
#include "../../fmt/format.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
|
@ -26,7 +27,7 @@ bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPt
|
|||
*o = &stack_get(v,idx);
|
||||
if(type(**o) != type){
|
||||
SQObjectPtr oval = v->PrintObjVal(**o);
|
||||
v->Raise_Error("wrong argument type, expected '%s' got '%.50s'",IdType2Name(type),_stringval(oval));
|
||||
v->Raise_Error(fmt::format("wrong argument type, expected '{}' got '{:.50s}'",IdType2Name(type),_stringval(oval)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
#include "../../fmt/format.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
|
@ -214,7 +215,7 @@ static SQInteger base_array(HSQUIRRELVM v)
|
|||
SQInteger nInitialSize = tointeger(stack_get(v,2));
|
||||
SQInteger ret = 1;
|
||||
if (nInitialSize < 0) {
|
||||
v->Raise_Error("can't create/resize array with/to size " OTTD_PRINTF64, nInitialSize);
|
||||
v->Raise_Error(fmt::format("can't create/resize array with/to size {}", nInitialSize));
|
||||
nInitialSize = 0;
|
||||
ret = -1;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "../../fmt/format.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
#include "../../fmt/format.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
|
@ -63,16 +64,9 @@ SQRESULT sq_stackinfos(HSQUIRRELVM v, SQInteger level, SQStackInfos *si)
|
|||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
void SQVM::Raise_Error(const SQChar *s, ...)
|
||||
void SQVM::Raise_Error(const std::string &msg)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
size_t len = strlen(s)+(NUMBER_MAX_CHAR*2);
|
||||
char *buffer = MallocT<char>(len + 1);
|
||||
vseprintf(buffer, buffer + len, s, vl);
|
||||
va_end(vl);
|
||||
_lasterror = SQString::Create(_ss(this),buffer,-1);
|
||||
free(buffer);
|
||||
_lasterror = SQString::Create(_ss(this),msg.c_str(),-1);
|
||||
}
|
||||
|
||||
void SQVM::Raise_Error(SQObjectPtr &desc)
|
||||
|
@ -99,13 +93,13 @@ SQString *SQVM::PrintObjVal(const SQObject &o)
|
|||
void SQVM::Raise_IdxError(const SQObject &o)
|
||||
{
|
||||
SQObjectPtr oval = PrintObjVal(o);
|
||||
Raise_Error("the index '%.50s' does not exist", _stringval(oval));
|
||||
Raise_Error(fmt::format("the index '{:.50s}' does not exist", _stringval(oval)));
|
||||
}
|
||||
|
||||
void SQVM::Raise_CompareError(const SQObject &o1, const SQObject &o2)
|
||||
{
|
||||
SQObjectPtr oval1 = PrintObjVal(o1), oval2 = PrintObjVal(o2);
|
||||
Raise_Error("comparison between '%.50s' and '%.50s'", _stringval(oval1), _stringval(oval2));
|
||||
Raise_Error(fmt::format("comparison between '{:.50s}' and '{:.50s}'", _stringval(oval1), _stringval(oval2)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -122,5 +116,5 @@ void SQVM::Raise_ParamTypeError(SQInteger nparam,SQInteger typemask,SQInteger ty
|
|||
StringCat(exptypes,SQString::Create(_ss(this), IdType2Name((SQObjectType)mask), -1), exptypes);
|
||||
}
|
||||
}
|
||||
Raise_Error("parameter " OTTD_PRINTF64 " has an invalid type '%s' ; expected: '%s'", nparam, IdType2Name((SQObjectType)type), _stringval(exptypes));
|
||||
Raise_Error(fmt::format("parameter {} has an invalid type '{}' ; expected: '{}'", nparam, IdType2Name((SQObjectType)type), _stringval(exptypes)));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
#include "../../fmt/format.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
|
@ -283,7 +284,7 @@ bool WriteObject(HSQUIRRELVM v,SQUserPointer up,SQWRITEFUNC write,SQObjectPtr &o
|
|||
case OT_NULL:
|
||||
break;
|
||||
default:
|
||||
v->Raise_Error("cannot serialize a %s",GetTypeName(o));
|
||||
v->Raise_Error(fmt::format("cannot serialize a {}",GetTypeName(o)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -313,7 +314,7 @@ bool ReadObject(HSQUIRRELVM v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &o)
|
|||
o=_null_;
|
||||
break;
|
||||
default:
|
||||
v->Raise_Error("cannot serialize a %s",IdType2Name(t));
|
||||
v->Raise_Error(fmt::format("cannot serialize a {}",IdType2Name(t)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
#include "../../fmt/format.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
|
@ -54,7 +55,7 @@ bool SQVM::BW_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,con
|
|||
default: { Raise_Error("internal vm error bitwise op failed"); return false; }
|
||||
}
|
||||
}
|
||||
else { Raise_Error("bitwise op between '%s' and '%s'",GetTypeName(o1),GetTypeName(o2)); return false;}
|
||||
else { Raise_Error(fmt::format("bitwise op between '{}' and '{}'",GetTypeName(o1),GetTypeName(o2))); return false;}
|
||||
trg = res;
|
||||
return true;
|
||||
}
|
||||
|
@ -94,7 +95,7 @@ bool SQVM::ARITH_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1,
|
|||
if(!StringCat(o1, o2, trg)) return false;
|
||||
}
|
||||
else if(!ArithMetaMethod(op,o1,o2,trg)) {
|
||||
Raise_Error("arith op %c on between '%s' and '%s'",(char)op,GetTypeName(o1),GetTypeName(o2)); return false;
|
||||
Raise_Error(fmt::format("arith op {} on between '{}' and '{}'",(char)op,GetTypeName(o1),GetTypeName(o2))); return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -183,7 +184,7 @@ bool SQVM::NEG_OP(SQObjectPtr &trg,const SQObjectPtr &o)
|
|||
}
|
||||
default:break; //shutup compiler
|
||||
}
|
||||
Raise_Error("attempt to negate a %s", GetTypeName(o));
|
||||
Raise_Error(fmt::format("attempt to negate a {}", GetTypeName(o)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -540,14 +541,14 @@ bool SQVM::FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr
|
|||
}
|
||||
FALLTHROUGH;
|
||||
default:
|
||||
Raise_Error("cannot iterate %s", GetTypeName(o1));
|
||||
Raise_Error(fmt::format("cannot iterate {}", GetTypeName(o1)));
|
||||
}
|
||||
return false; //cannot be hit(just to avoid warnings)
|
||||
}
|
||||
|
||||
bool SQVM::DELEGATE_OP(SQObjectPtr &trg,SQObjectPtr &o1,SQObjectPtr &o2)
|
||||
{
|
||||
if(type(o1) != OT_TABLE) { Raise_Error("delegating a '%s'", GetTypeName(o1)); return false; }
|
||||
if(type(o1) != OT_TABLE) { Raise_Error(fmt::format("delegating a '{}'", GetTypeName(o1))); return false; }
|
||||
switch(type(o2)) {
|
||||
case OT_TABLE:
|
||||
if(!_table(o1)->SetDelegate(_table(o2))){
|
||||
|
@ -559,7 +560,7 @@ bool SQVM::DELEGATE_OP(SQObjectPtr &trg,SQObjectPtr &o1,SQObjectPtr &o2)
|
|||
_table(o1)->SetDelegate(nullptr);
|
||||
break;
|
||||
default:
|
||||
Raise_Error("using '%s' as delegate", GetTypeName(o2));
|
||||
Raise_Error(fmt::format("using '{}' as delegate", GetTypeName(o2)));
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
@ -615,7 +616,7 @@ bool SQVM::GETVARGV_OP(SQObjectPtr &target,SQObjectPtr &index,CallInfo *ci)
|
|||
return false;
|
||||
}
|
||||
if(!sq_isnumeric(index)){
|
||||
Raise_Error("indexing 'vargv' with %s",GetTypeName(index));
|
||||
Raise_Error(fmt::format("indexing 'vargv' with {}",GetTypeName(index)));
|
||||
return false;
|
||||
}
|
||||
SQInteger idx = tointeger(index);
|
||||
|
@ -629,7 +630,7 @@ bool SQVM::CLASS_OP(SQObjectPtr &target,SQInteger baseclass,SQInteger attributes
|
|||
SQClass *base = nullptr;
|
||||
SQObjectPtr attrs;
|
||||
if(baseclass != -1) {
|
||||
if(type(_stack._vals[_stackbase+baseclass]) != OT_CLASS) { Raise_Error("trying to inherit from a %s",GetTypeName(_stack._vals[_stackbase+baseclass])); return false; }
|
||||
if(type(_stack._vals[_stackbase+baseclass]) != OT_CLASS) { Raise_Error(fmt::format("trying to inherit from a {}",GetTypeName(_stack._vals[_stackbase+baseclass]))); return false; }
|
||||
base = _class(_stack._vals[_stackbase + baseclass]);
|
||||
}
|
||||
if(attributes != MAX_FUNC_STACKSIZE) {
|
||||
|
@ -684,7 +685,7 @@ bool SQVM::GETPARENT_OP(SQObjectPtr &o,SQObjectPtr &target)
|
|||
case OT_CLASS: target = _class(o)->_base?_class(o)->_base:_null_;
|
||||
break;
|
||||
default:
|
||||
Raise_Error("the %s type doesn't have a parent slot", GetTypeName(o));
|
||||
Raise_Error(fmt::format("the {} type doesn't have a parent slot", GetTypeName(o)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -839,11 +840,11 @@ common_call:
|
|||
STK(ct_target) = clo;
|
||||
break;
|
||||
}
|
||||
Raise_Error("attempt to call '%s'", GetTypeName(clo));
|
||||
Raise_Error(fmt::format("attempt to call '{}'", GetTypeName(clo)));
|
||||
SQ_THROW();
|
||||
}
|
||||
default:
|
||||
Raise_Error("attempt to call '%s'", GetTypeName(clo));
|
||||
Raise_Error(fmt::format("attempt to call '{}'", GetTypeName(clo)));
|
||||
SQ_THROW();
|
||||
}
|
||||
}
|
||||
|
@ -945,7 +946,7 @@ common_call:
|
|||
case _OP_EXISTS: TARGET = Get(STK(arg1), STK(arg2), temp_reg, true,false)?_true_:_false_;continue;
|
||||
case _OP_INSTANCEOF:
|
||||
if(type(STK(arg1)) != OT_CLASS || type(STK(arg2)) != OT_INSTANCE)
|
||||
{Raise_Error("cannot apply instanceof between a %s and a %s",GetTypeName(STK(arg1)),GetTypeName(STK(arg2))); SQ_THROW();}
|
||||
{Raise_Error(fmt::format("cannot apply instanceof between a {} and a {}",GetTypeName(STK(arg1)),GetTypeName(STK(arg2)))); SQ_THROW();}
|
||||
TARGET = _instance(STK(arg2))->InstanceOf(_class(STK(arg1)))?_true_:_false_;
|
||||
continue;
|
||||
case _OP_AND:
|
||||
|
@ -968,7 +969,7 @@ common_call:
|
|||
TARGET = SQInteger(~t);
|
||||
continue;
|
||||
}
|
||||
Raise_Error("attempt to perform a bitwise op on a %s", GetTypeName(STK(arg1)));
|
||||
Raise_Error(fmt::format("attempt to perform a bitwise op on a {}", GetTypeName(STK(arg1))));
|
||||
SQ_THROW();
|
||||
case _OP_CLOSURE: {
|
||||
SQClosure *c = ci->_closure._unVal.pClosure;
|
||||
|
@ -983,7 +984,7 @@ common_call:
|
|||
traps -= ci->_etraps;
|
||||
if(sarg1 != MAX_FUNC_STACKSIZE) STK(arg1) = temp_reg;
|
||||
}
|
||||
else { Raise_Error("trying to yield a '%s',only genenerator can be yielded", GetTypeName(ci->_closure)); SQ_THROW();}
|
||||
else { Raise_Error(fmt::format("trying to yield a '{}',only genenerator can be yielded", GetTypeName(ci->_closure))); SQ_THROW();}
|
||||
if(Return(arg0, arg1, temp_reg)){
|
||||
assert(traps == 0);
|
||||
outres = temp_reg;
|
||||
|
@ -993,7 +994,7 @@ common_call:
|
|||
}
|
||||
continue;
|
||||
case _OP_RESUME:
|
||||
if(type(STK(arg1)) != OT_GENERATOR){ Raise_Error("trying to resume a '%s',only genenerator can be resumed", GetTypeName(STK(arg1))); SQ_THROW();}
|
||||
if(type(STK(arg1)) != OT_GENERATOR){ Raise_Error(fmt::format("trying to resume a '{}',only genenerator can be resumed", GetTypeName(STK(arg1)))); SQ_THROW();}
|
||||
_GUARD(_generator(STK(arg1))->Resume(this, arg0));
|
||||
traps += ci->_etraps;
|
||||
continue;
|
||||
|
@ -1009,7 +1010,7 @@ common_call:
|
|||
case _OP_DELEGATE: _GUARD(DELEGATE_OP(TARGET,STK(arg1),STK(arg2))); continue;
|
||||
case _OP_CLONE:
|
||||
if(!Clone(STK(arg1), TARGET))
|
||||
{ Raise_Error("cloning a %s", GetTypeName(STK(arg1))); SQ_THROW();}
|
||||
{ Raise_Error(fmt::format("cloning a {}", GetTypeName(STK(arg1)))); SQ_THROW();}
|
||||
continue;
|
||||
case _OP_TYPEOF: TypeOf(STK(arg1), TARGET); continue;
|
||||
case _OP_PUSHTRAP:{
|
||||
|
@ -1348,10 +1349,10 @@ bool SQVM::Set(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr
|
|||
}
|
||||
break;
|
||||
case OT_ARRAY:
|
||||
if(!sq_isnumeric(key)) {Raise_Error("indexing %s with %s",GetTypeName(self),GetTypeName(key)); return false; }
|
||||
if(!sq_isnumeric(key)) {Raise_Error(fmt::format("indexing {} with {}",GetTypeName(self),GetTypeName(key))); return false; }
|
||||
return _array(self)->Set(tointeger(key),val);
|
||||
default:
|
||||
Raise_Error("trying to set '%s'",GetTypeName(self));
|
||||
Raise_Error(fmt::format("trying to set '{}'",GetTypeName(self)));
|
||||
return false;
|
||||
}
|
||||
if(fetchroot) {
|
||||
|
@ -1420,13 +1421,13 @@ bool SQVM::NewSlot(const SQObjectPtr &self,const SQObjectPtr &key,const SQObject
|
|||
}
|
||||
else {
|
||||
SQObjectPtr oval = PrintObjVal(key);
|
||||
Raise_Error("the property '%s' already exists",_stringval(oval));
|
||||
Raise_Error(fmt::format("the property '{}' already exists",_stringval(oval)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Raise_Error("indexing %s with %s",GetTypeName(self),GetTypeName(key));
|
||||
Raise_Error(fmt::format("indexing {} with {}",GetTypeName(self),GetTypeName(key)));
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
@ -1457,7 +1458,7 @@ bool SQVM::DeleteSlot(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr
|
|||
}
|
||||
}
|
||||
else {
|
||||
Raise_Error("cannot delete a slot from %s",GetTypeName(self));
|
||||
Raise_Error(fmt::format("cannot delete a slot from {}",GetTypeName(self)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1465,7 +1466,7 @@ bool SQVM::DeleteSlot(const SQObjectPtr &self,const SQObjectPtr &key,SQObjectPtr
|
|||
}
|
||||
break;
|
||||
default:
|
||||
Raise_Error("attempt to delete a slot from a %s",GetTypeName(self));
|
||||
Raise_Error(fmt::format("attempt to delete a slot from a {}",GetTypeName(self)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -80,7 +80,7 @@ public:
|
|||
SQString *PrintObjVal(const SQObject &o);
|
||||
|
||||
|
||||
void Raise_Error(const SQChar *s, ...) WARN_FORMAT(2, 3);
|
||||
void Raise_Error(const std::string &msg);
|
||||
void Raise_Error(SQObjectPtr &desc);
|
||||
void Raise_IdxError(const SQObject &o);
|
||||
void Raise_CompareError(const SQObject &o1, const SQObject &o2);
|
||||
|
|
Loading…
Reference in New Issue