[DEV] remove sq_is*()
This commit is contained in:
parent
fa206b5e49
commit
b6c6a38844
@ -132,6 +132,63 @@ namespace rabbit {
|
|||||||
uint64_t toRaw() const {
|
uint64_t toRaw() const {
|
||||||
return _unVal.raw;
|
return _unVal.raw;
|
||||||
}
|
}
|
||||||
|
bool isNumeric() const {
|
||||||
|
return (_type & SQOBJECT_NUMERIC) != 0;
|
||||||
|
}
|
||||||
|
bool isTable() const {
|
||||||
|
return _type == rabbit::OT_TABLE;
|
||||||
|
}
|
||||||
|
bool isArray() const {
|
||||||
|
return _type == rabbit::OT_ARRAY;
|
||||||
|
}
|
||||||
|
bool isFunctionProto() const {
|
||||||
|
return _type == rabbit::OT_FUNCPROTO;
|
||||||
|
}
|
||||||
|
bool isClosure() const {
|
||||||
|
return _type == rabbit::OT_CLOSURE;
|
||||||
|
}
|
||||||
|
bool isGenerator() const {
|
||||||
|
return _type == rabbit::OT_GENERATOR;
|
||||||
|
}
|
||||||
|
bool isNativeClosure() const {
|
||||||
|
return _type == rabbit::OT_NATIVECLOSURE;
|
||||||
|
}
|
||||||
|
bool isString() const {
|
||||||
|
return _type == rabbit::OT_STRING;
|
||||||
|
}
|
||||||
|
bool isInteger() const {
|
||||||
|
return _type == rabbit::OT_INTEGER;
|
||||||
|
}
|
||||||
|
bool isFloat() const {
|
||||||
|
return _type == rabbit::OT_FLOAT;
|
||||||
|
}
|
||||||
|
bool isUserPointer() const {
|
||||||
|
return _type == rabbit::OT_USERPOINTER;
|
||||||
|
}
|
||||||
|
bool isUserData() const {
|
||||||
|
return _type == rabbit::OT_USERDATA;
|
||||||
|
}
|
||||||
|
bool isVirtualMachine() const {
|
||||||
|
return _type == rabbit::OT_THREAD;
|
||||||
|
}
|
||||||
|
bool isNull() const {
|
||||||
|
return _type == rabbit::OT_NULL;
|
||||||
|
}
|
||||||
|
bool isClass() const {
|
||||||
|
return _type == rabbit::OT_CLASS;
|
||||||
|
}
|
||||||
|
bool isInstance() const {
|
||||||
|
return _type == rabbit::OT_INSTANCE;
|
||||||
|
}
|
||||||
|
bool isBoolean() const {
|
||||||
|
return _type == rabbit::OT_BOOL;
|
||||||
|
}
|
||||||
|
bool isWeakRef() const {
|
||||||
|
return _type == rabbit::OT_WEAKREF;
|
||||||
|
}
|
||||||
|
rabbit::ObjectType getType() const {
|
||||||
|
return _type;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define __addRef(type,unval) if(ISREFCOUNTED(type)) \
|
#define __addRef(type,unval) if(ISREFCOUNTED(type)) \
|
||||||
@ -155,24 +212,6 @@ namespace rabbit {
|
|||||||
#define tofloat(num) ((sq_type(num)==rabbit::OT_INTEGER)?(float_t)(num).toInteger():(num).toFloat())
|
#define tofloat(num) ((sq_type(num)==rabbit::OT_INTEGER)?(float_t)(num).toInteger():(num).toFloat())
|
||||||
#define tointeger(num) ((sq_type(num)==rabbit::OT_FLOAT)?(int64_t)(num).toFloat():(num).toInteger())
|
#define tointeger(num) ((sq_type(num)==rabbit::OT_FLOAT)?(int64_t)(num).toFloat():(num).toInteger())
|
||||||
|
|
||||||
#define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)
|
|
||||||
#define sq_istable(o) ((o)._type==rabbit::OT_TABLE)
|
|
||||||
#define sq_isarray(o) ((o)._type==rabbit::OT_ARRAY)
|
|
||||||
#define sq_isfunction(o) ((o)._type==rabbit::OT_FUNCPROTO)
|
|
||||||
#define sq_isclosure(o) ((o)._type==rabbit::OT_CLOSURE)
|
|
||||||
#define sq_isgenerator(o) ((o)._type==rabbit::OT_GENERATOR)
|
|
||||||
#define sq_isnativeclosure(o) ((o)._type==rabbit::OT_NATIVECLOSURE)
|
|
||||||
#define sq_isstring(o) ((o)._type==rabbit::OT_STRING)
|
|
||||||
#define sq_isinteger(o) ((o)._type==rabbit::OT_INTEGER)
|
|
||||||
#define sq_isfloat(o) ((o)._type==rabbit::OT_FLOAT)
|
|
||||||
#define sq_isuserpointer(o) ((o)._type==rabbit::OT_USERPOINTER)
|
|
||||||
#define sq_isuserdata(o) ((o)._type==rabbit::OT_USERDATA)
|
|
||||||
#define sq_isthread(o) ((o)._type==rabbit::OT_THREAD)
|
|
||||||
#define sq_isnull(o) ((o)._type==rabbit::OT_NULL)
|
|
||||||
#define sq_isclass(o) ((o)._type==rabbit::OT_CLASS)
|
|
||||||
#define sq_isinstance(o) ((o)._type==rabbit::OT_INSTANCE)
|
|
||||||
#define sq_isbool(o) ((o)._type==rabbit::OT_BOOL)
|
|
||||||
#define sq_isweakref(o) ((o)._type==rabbit::OT_WEAKREF)
|
|
||||||
#define sq_type(o) ((o)._type)
|
#define sq_type(o) ((o)._type)
|
||||||
|
|
||||||
inline void _Swap(rabbit::Object &a,rabbit::Object &b)
|
inline void _Swap(rabbit::Object &a,rabbit::Object &b)
|
||||||
|
@ -263,7 +263,8 @@ bool rabbit::VirtualMachine::objCmp(const rabbit::ObjectPtr &o1,const rabbit::Ob
|
|||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(sq_isnumeric(o1) && sq_isnumeric(o2)){
|
if( o1.isNumeric() ==true
|
||||||
|
&& o2.isNumeric() == true){
|
||||||
if((t1==rabbit::OT_INTEGER) && (t2==OT_FLOAT)) {
|
if((t1==rabbit::OT_INTEGER) && (t2==OT_FLOAT)) {
|
||||||
if( o1.toInteger()==o2.toFloat() ) { _RET_SUCCEED(0); }
|
if( o1.toInteger()==o2.toFloat() ) { _RET_SUCCEED(0); }
|
||||||
else if( o1.toInteger()<o2.toFloat() ) { _RET_SUCCEED(-1); }
|
else if( o1.toInteger()<o2.toFloat() ) { _RET_SUCCEED(-1); }
|
||||||
@ -662,7 +663,7 @@ bool rabbit::VirtualMachine::isEqual(const rabbit::ObjectPtr &o1,const rabbit::O
|
|||||||
res = (o1.toRaw() == o2.toRaw());
|
res = (o1.toRaw() == o2.toRaw());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(sq_isnumeric(o1) && sq_isnumeric(o2)) {
|
if(o1.isNumeric() && o2.isNumeric()) {
|
||||||
res = (tofloat(o1) == tofloat(o2));
|
res = (tofloat(o1) == tofloat(o2));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1249,7 +1250,7 @@ bool rabbit::VirtualMachine::get(const rabbit::ObjectPtr &self, const rabbit::Ob
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case rabbit::OT_ARRAY:
|
case rabbit::OT_ARRAY:
|
||||||
if (sq_isnumeric(key)) {
|
if (key.isNumeric() == true) {
|
||||||
if (self.toArray()->get(tointeger(key), dest)) {
|
if (self.toArray()->get(tointeger(key), dest)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1270,7 +1271,7 @@ bool rabbit::VirtualMachine::get(const rabbit::ObjectPtr &self, const rabbit::Ob
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case rabbit::OT_STRING:
|
case rabbit::OT_STRING:
|
||||||
if(sq_isnumeric(key)){
|
if(key.isNumeric()){
|
||||||
int64_t n = tointeger(key);
|
int64_t n = tointeger(key);
|
||||||
int64_t len = self.toString()->_len;
|
int64_t len = self.toString()->_len;
|
||||||
if (n < 0) { n += len; }
|
if (n < 0) { n += len; }
|
||||||
@ -1380,7 +1381,7 @@ bool rabbit::VirtualMachine::set(const rabbit::ObjectPtr &self,const rabbit::Obj
|
|||||||
if(const_cast<rabbit::Instance*>(self.toInstance())->set(key,val)) return true;
|
if(const_cast<rabbit::Instance*>(self.toInstance())->set(key,val)) return true;
|
||||||
break;
|
break;
|
||||||
case rabbit::OT_ARRAY:
|
case rabbit::OT_ARRAY:
|
||||||
if(!sq_isnumeric(key)) { raise_error("indexing %s with %s",getTypeName(self),getTypeName(key)); return false; }
|
if(key.isNumeric() == false) { raise_error("indexing %s with %s",getTypeName(self),getTypeName(key)); return false; }
|
||||||
if(!self.toArray()->set(tointeger(key),val)) {
|
if(!self.toArray()->set(tointeger(key),val)) {
|
||||||
raise_Idxerror(key);
|
raise_Idxerror(key);
|
||||||
return false;
|
return false;
|
||||||
|
@ -108,7 +108,9 @@ int64_t rabbit::sq_getvmstate(rabbit::VirtualMachine* v)
|
|||||||
void rabbit::sq_seterrorhandler(rabbit::VirtualMachine* v)
|
void rabbit::sq_seterrorhandler(rabbit::VirtualMachine* v)
|
||||||
{
|
{
|
||||||
rabbit::Object o = stack_get(v, -1);
|
rabbit::Object o = stack_get(v, -1);
|
||||||
if(sq_isclosure(o) || sq_isnativeclosure(o) || sq_isnull(o)) {
|
if( o.isClosure() == true
|
||||||
|
|| o.isNativeClosure() == true
|
||||||
|
|| o.isNull() == true) {
|
||||||
v->_errorhandler = o;
|
v->_errorhandler = o;
|
||||||
v->pop();
|
v->pop();
|
||||||
}
|
}
|
||||||
@ -124,10 +126,12 @@ void rabbit::sq_setnativedebughook(rabbit::VirtualMachine* v,SQDEBUGHOOK hook)
|
|||||||
void rabbit::sq_setdebughook(rabbit::VirtualMachine* v)
|
void rabbit::sq_setdebughook(rabbit::VirtualMachine* v)
|
||||||
{
|
{
|
||||||
rabbit::Object o = stack_get(v,-1);
|
rabbit::Object o = stack_get(v,-1);
|
||||||
if(sq_isclosure(o) || sq_isnativeclosure(o) || sq_isnull(o)) {
|
if ( o.isClosure() == true
|
||||||
|
|| o.isNativeClosure() == true
|
||||||
|
|| o.isNull() == true) {
|
||||||
v->_debughook_closure = o;
|
v->_debughook_closure = o;
|
||||||
v->_debughook_native = NULL;
|
v->_debughook_native = NULL;
|
||||||
v->_debughook = !sq_isnull(o);
|
v->_debughook = ! o.isNull();
|
||||||
v->pop();
|
v->pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +208,7 @@ const char * rabbit::sq_objtostring(const rabbit::Object *o)
|
|||||||
|
|
||||||
int64_t rabbit::sq_objtointeger(const rabbit::Object *o)
|
int64_t rabbit::sq_objtointeger(const rabbit::Object *o)
|
||||||
{
|
{
|
||||||
if(sq_isnumeric(*o)) {
|
if(o->isNumeric() == true) {
|
||||||
return tointeger(*o);
|
return tointeger(*o);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -212,7 +216,7 @@ int64_t rabbit::sq_objtointeger(const rabbit::Object *o)
|
|||||||
|
|
||||||
float_t rabbit::sq_objtofloat(const rabbit::Object *o)
|
float_t rabbit::sq_objtofloat(const rabbit::Object *o)
|
||||||
{
|
{
|
||||||
if(sq_isnumeric(*o)) {
|
if(o->isNumeric() == true) {
|
||||||
return tofloat(*o);
|
return tofloat(*o);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -220,7 +224,7 @@ float_t rabbit::sq_objtofloat(const rabbit::Object *o)
|
|||||||
|
|
||||||
rabbit::Bool rabbit::sq_objtobool(const rabbit::Object *o)
|
rabbit::Bool rabbit::sq_objtobool(const rabbit::Object *o)
|
||||||
{
|
{
|
||||||
if(sq_isbool(*o)) {
|
if(o->isBoolean() == true) {
|
||||||
return o->toInteger();
|
return o->toInteger();
|
||||||
}
|
}
|
||||||
return SQFalse;
|
return SQFalse;
|
||||||
@ -228,7 +232,7 @@ rabbit::Bool rabbit::sq_objtobool(const rabbit::Object *o)
|
|||||||
|
|
||||||
rabbit::UserPointer rabbit::sq_objtouserpointer(const rabbit::Object *o)
|
rabbit::UserPointer rabbit::sq_objtouserpointer(const rabbit::Object *o)
|
||||||
{
|
{
|
||||||
if(sq_isuserpointer(*o)) {
|
if(o->isUserPointer() == true) {
|
||||||
return o->toUserPointer();
|
return o->toUserPointer();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -429,7 +433,7 @@ rabbit::Result rabbit::sq_getclosureinfo(rabbit::VirtualMachine* v,int64_t idx,u
|
|||||||
rabbit::Result rabbit::sq_setnativeclosurename(rabbit::VirtualMachine* v,int64_t idx,const char *name)
|
rabbit::Result rabbit::sq_setnativeclosurename(rabbit::VirtualMachine* v,int64_t idx,const char *name)
|
||||||
{
|
{
|
||||||
rabbit::Object o = stack_get(v, idx);
|
rabbit::Object o = stack_get(v, idx);
|
||||||
if(sq_isnativeclosure(o)) {
|
if(o.isNativeClosure() == true) {
|
||||||
rabbit::NativeClosure *nc = o.toNativeClosure();
|
rabbit::NativeClosure *nc = o.toNativeClosure();
|
||||||
nc->_name = rabbit::String::create(_get_shared_state(v),name);
|
nc->_name = rabbit::String::create(_get_shared_state(v),name);
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
@ -440,7 +444,7 @@ rabbit::Result rabbit::sq_setnativeclosurename(rabbit::VirtualMachine* v,int64_t
|
|||||||
rabbit::Result rabbit::sq_setparamscheck(rabbit::VirtualMachine* v,int64_t nparamscheck,const char *typemask)
|
rabbit::Result rabbit::sq_setparamscheck(rabbit::VirtualMachine* v,int64_t nparamscheck,const char *typemask)
|
||||||
{
|
{
|
||||||
rabbit::Object o = stack_get(v, -1);
|
rabbit::Object o = stack_get(v, -1);
|
||||||
if(!sq_isnativeclosure(o))
|
if(o.isNativeClosure() == false)
|
||||||
return sq_throwerror(v, "native closure expected");
|
return sq_throwerror(v, "native closure expected");
|
||||||
rabbit::NativeClosure *nc = o.toNativeClosure();
|
rabbit::NativeClosure *nc = o.toNativeClosure();
|
||||||
nc->_nparamscheck = nparamscheck;
|
nc->_nparamscheck = nparamscheck;
|
||||||
@ -462,18 +466,20 @@ rabbit::Result rabbit::sq_setparamscheck(rabbit::VirtualMachine* v,int64_t npara
|
|||||||
rabbit::Result rabbit::sq_bindenv(rabbit::VirtualMachine* v,int64_t idx)
|
rabbit::Result rabbit::sq_bindenv(rabbit::VirtualMachine* v,int64_t idx)
|
||||||
{
|
{
|
||||||
rabbit::ObjectPtr &o = stack_get(v,idx);
|
rabbit::ObjectPtr &o = stack_get(v,idx);
|
||||||
if(!sq_isnativeclosure(o) &&
|
if( o.isNativeClosure() == false
|
||||||
!sq_isclosure(o))
|
&& o.isClosure() == false) {
|
||||||
return sq_throwerror(v, "the target is not a closure");
|
return sq_throwerror(v, "the target is not a closure");
|
||||||
|
}
|
||||||
rabbit::ObjectPtr &env = stack_get(v,-1);
|
rabbit::ObjectPtr &env = stack_get(v,-1);
|
||||||
if(!sq_istable(env) &&
|
if ( env.isTable() == false
|
||||||
!sq_isarray(env) &&
|
&& env.isArray() ==false
|
||||||
!sq_isclass(env) &&
|
&& env.isClass() == false
|
||||||
!sq_isinstance(env))
|
&& env.isInstance() == false) {
|
||||||
return sq_throwerror(v,"invalid environment");
|
return sq_throwerror(v,"invalid environment");
|
||||||
|
}
|
||||||
rabbit::WeakRef *w = env.toRefCounted()->getWeakRef(sq_type(env));
|
rabbit::WeakRef *w = env.toRefCounted()->getWeakRef(sq_type(env));
|
||||||
rabbit::ObjectPtr ret;
|
rabbit::ObjectPtr ret;
|
||||||
if(sq_isclosure(o)) {
|
if(o.isClosure() == true) {
|
||||||
rabbit::Closure *c = o.toClosure()->clone();
|
rabbit::Closure *c = o.toClosure()->clone();
|
||||||
__Objrelease(c->_env);
|
__Objrelease(c->_env);
|
||||||
c->_env = w;
|
c->_env = w;
|
||||||
@ -499,14 +505,14 @@ rabbit::Result rabbit::sq_bindenv(rabbit::VirtualMachine* v,int64_t idx)
|
|||||||
rabbit::Result rabbit::sq_getclosurename(rabbit::VirtualMachine* v,int64_t idx)
|
rabbit::Result rabbit::sq_getclosurename(rabbit::VirtualMachine* v,int64_t idx)
|
||||||
{
|
{
|
||||||
rabbit::ObjectPtr &o = stack_get(v,idx);
|
rabbit::ObjectPtr &o = stack_get(v,idx);
|
||||||
if(!sq_isnativeclosure(o) &&
|
if ( o.isNativeClosure() == false
|
||||||
!sq_isclosure(o))
|
&& o.isClosure() == false) {
|
||||||
return sq_throwerror(v,"the target is not a closure");
|
return sq_throwerror(v,"the target is not a closure");
|
||||||
if(sq_isnativeclosure(o))
|
|
||||||
{
|
|
||||||
v->push(o.toNativeClosure()->_name);
|
|
||||||
}
|
}
|
||||||
else { //closure
|
if (o.isNativeClosure() == true) {
|
||||||
|
v->push(o.toNativeClosure()->_name);
|
||||||
|
} else {
|
||||||
|
//closure
|
||||||
v->push(o.toClosure()->_function->_name);
|
v->push(o.toClosure()->_function->_name);
|
||||||
}
|
}
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
@ -516,8 +522,10 @@ rabbit::Result rabbit::sq_setclosureroot(rabbit::VirtualMachine* v,int64_t idx)
|
|||||||
{
|
{
|
||||||
rabbit::ObjectPtr &c = stack_get(v,idx);
|
rabbit::ObjectPtr &c = stack_get(v,idx);
|
||||||
rabbit::Object o = stack_get(v, -1);
|
rabbit::Object o = stack_get(v, -1);
|
||||||
if(!sq_isclosure(c)) return sq_throwerror(v, "closure expected");
|
if(c.isClosure() == false) {
|
||||||
if(sq_istable(o)) {
|
return sq_throwerror(v, "closure expected");
|
||||||
|
}
|
||||||
|
if(o.isTable() == true) {
|
||||||
c.toClosure()->setRoot(o.toTable()->getWeakRef(rabbit::OT_TABLE));
|
c.toClosure()->setRoot(o.toTable()->getWeakRef(rabbit::OT_TABLE));
|
||||||
v->pop();
|
v->pop();
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
@ -528,7 +536,9 @@ rabbit::Result rabbit::sq_setclosureroot(rabbit::VirtualMachine* v,int64_t idx)
|
|||||||
rabbit::Result rabbit::sq_getclosureroot(rabbit::VirtualMachine* v,int64_t idx)
|
rabbit::Result rabbit::sq_getclosureroot(rabbit::VirtualMachine* v,int64_t idx)
|
||||||
{
|
{
|
||||||
rabbit::ObjectPtr &c = stack_get(v,idx);
|
rabbit::ObjectPtr &c = stack_get(v,idx);
|
||||||
if(!sq_isclosure(c)) return sq_throwerror(v, "closure expected");
|
if(c.isClosure() == false) {
|
||||||
|
return sq_throwerror(v, "closure expected");
|
||||||
|
}
|
||||||
v->push(c.toClosure()->_root->_obj);
|
v->push(c.toClosure()->_root->_obj);
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
@ -565,7 +575,8 @@ void rabbit::sq_pushconsttable(rabbit::VirtualMachine* v)
|
|||||||
rabbit::Result rabbit::sq_setroottable(rabbit::VirtualMachine* v)
|
rabbit::Result rabbit::sq_setroottable(rabbit::VirtualMachine* v)
|
||||||
{
|
{
|
||||||
rabbit::Object o = stack_get(v, -1);
|
rabbit::Object o = stack_get(v, -1);
|
||||||
if(sq_istable(o) || sq_isnull(o)) {
|
if ( o.isTable() == true
|
||||||
|
|| o.isNull() == true) {
|
||||||
v->_roottable = o;
|
v->_roottable = o;
|
||||||
v->pop();
|
v->pop();
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
@ -576,7 +587,7 @@ rabbit::Result rabbit::sq_setroottable(rabbit::VirtualMachine* v)
|
|||||||
rabbit::Result rabbit::sq_setconsttable(rabbit::VirtualMachine* v)
|
rabbit::Result rabbit::sq_setconsttable(rabbit::VirtualMachine* v)
|
||||||
{
|
{
|
||||||
rabbit::Object o = stack_get(v, -1);
|
rabbit::Object o = stack_get(v, -1);
|
||||||
if(sq_istable(o)) {
|
if (o.isTable() == true) {
|
||||||
_get_shared_state(v)->_consts = o;
|
_get_shared_state(v)->_consts = o;
|
||||||
v->pop();
|
v->pop();
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
@ -665,11 +676,11 @@ void rabbit::sq_tobool(rabbit::VirtualMachine* v, int64_t idx, rabbit::Bool *b)
|
|||||||
rabbit::Result rabbit::sq_getinteger(rabbit::VirtualMachine* v,int64_t idx,int64_t *i)
|
rabbit::Result rabbit::sq_getinteger(rabbit::VirtualMachine* v,int64_t idx,int64_t *i)
|
||||||
{
|
{
|
||||||
rabbit::ObjectPtr &o = stack_get(v, idx);
|
rabbit::ObjectPtr &o = stack_get(v, idx);
|
||||||
if(sq_isnumeric(o)) {
|
if(o.isNumeric() == true) {
|
||||||
*i = tointeger(o);
|
*i = tointeger(o);
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
if(sq_isbool(o)) {
|
if(o.isBoolean() == true) {
|
||||||
*i = rabbit::VirtualMachine::IsFalse(o)?SQFalse:SQTrue;
|
*i = rabbit::VirtualMachine::IsFalse(o)?SQFalse:SQTrue;
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
@ -679,7 +690,7 @@ rabbit::Result rabbit::sq_getinteger(rabbit::VirtualMachine* v,int64_t idx,int64
|
|||||||
rabbit::Result rabbit::sq_getfloat(rabbit::VirtualMachine* v,int64_t idx,float_t *f)
|
rabbit::Result rabbit::sq_getfloat(rabbit::VirtualMachine* v,int64_t idx,float_t *f)
|
||||||
{
|
{
|
||||||
rabbit::ObjectPtr &o = stack_get(v, idx);
|
rabbit::ObjectPtr &o = stack_get(v, idx);
|
||||||
if(sq_isnumeric(o)) {
|
if(o.isNumeric() == true) {
|
||||||
*f = tofloat(o);
|
*f = tofloat(o);
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
@ -689,7 +700,7 @@ rabbit::Result rabbit::sq_getfloat(rabbit::VirtualMachine* v,int64_t idx,float_t
|
|||||||
rabbit::Result rabbit::sq_getbool(rabbit::VirtualMachine* v,int64_t idx,rabbit::Bool *b)
|
rabbit::Result rabbit::sq_getbool(rabbit::VirtualMachine* v,int64_t idx,rabbit::Bool *b)
|
||||||
{
|
{
|
||||||
rabbit::ObjectPtr &o = stack_get(v, idx);
|
rabbit::ObjectPtr &o = stack_get(v, idx);
|
||||||
if(sq_isbool(o)) {
|
if (o.isBoolean() == true) {
|
||||||
*b = o.toInteger();
|
*b = o.toInteger();
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
@ -1083,7 +1094,7 @@ rabbit::Result rabbit::sq_rawget(rabbit::VirtualMachine* v,int64_t idx)
|
|||||||
break;
|
break;
|
||||||
case rabbit::OT_ARRAY:
|
case rabbit::OT_ARRAY:
|
||||||
{
|
{
|
||||||
if(sq_isnumeric(obj)){
|
if(obj.isNumeric() == true){
|
||||||
if(self.toArray()->get(tointeger(obj),obj)) {
|
if(self.toArray()->get(tointeger(obj),obj)) {
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
|
@ -176,13 +176,14 @@ static int64_t get_slice_params(rabbit::VirtualMachine* v,int64_t &sidx,int64_t
|
|||||||
o=stack_get(v,1);
|
o=stack_get(v,1);
|
||||||
if(top>1){
|
if(top>1){
|
||||||
rabbit::ObjectPtr &start=stack_get(v,2);
|
rabbit::ObjectPtr &start=stack_get(v,2);
|
||||||
if(sq_type(start)!=rabbit::OT_NULL && sq_isnumeric(start)){
|
if( sq_type(start)!=rabbit::OT_NULL
|
||||||
|
&& start.isNumeric() == true){
|
||||||
sidx=tointeger(start);
|
sidx=tointeger(start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(top>2){
|
if(top>2){
|
||||||
rabbit::ObjectPtr &end=stack_get(v,3);
|
rabbit::ObjectPtr &end=stack_get(v,3);
|
||||||
if(sq_isnumeric(end)){
|
if(end.isNumeric() == true){
|
||||||
eidx=tointeger(end);
|
eidx=tointeger(end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -562,7 +563,9 @@ static int64_t array_remove(rabbit::VirtualMachine* v)
|
|||||||
{
|
{
|
||||||
rabbit::Object &o = stack_get(v, 1);
|
rabbit::Object &o = stack_get(v, 1);
|
||||||
rabbit::Object &idx = stack_get(v, 2);
|
rabbit::Object &idx = stack_get(v, 2);
|
||||||
if(!sq_isnumeric(idx)) return sq_throwerror(v, "wrong type");
|
if(idx.isNumeric() == false) {
|
||||||
|
return sq_throwerror(v, "wrong type");
|
||||||
|
}
|
||||||
rabbit::ObjectPtr val;
|
rabbit::ObjectPtr val;
|
||||||
if(o.toArray()->get(tointeger(idx), val)) {
|
if(o.toArray()->get(tointeger(idx), val)) {
|
||||||
o.toArray()->remove(tointeger(idx));
|
o.toArray()->remove(tointeger(idx));
|
||||||
@ -577,7 +580,7 @@ static int64_t array_resize(rabbit::VirtualMachine* v)
|
|||||||
rabbit::Object &o = stack_get(v, 1);
|
rabbit::Object &o = stack_get(v, 1);
|
||||||
rabbit::Object &nsize = stack_get(v, 2);
|
rabbit::Object &nsize = stack_get(v, 2);
|
||||||
rabbit::ObjectPtr fill;
|
rabbit::ObjectPtr fill;
|
||||||
if(sq_isnumeric(nsize)) {
|
if (nsize.isNumeric() == true) {
|
||||||
int64_t sz = tointeger(nsize);
|
int64_t sz = tointeger(nsize);
|
||||||
if (sz<0)
|
if (sz<0)
|
||||||
return sq_throwerror(v, "resizing to negative length");
|
return sq_throwerror(v, "resizing to negative length");
|
||||||
@ -710,8 +713,9 @@ static bool _sort_compare(rabbit::VirtualMachine* v,rabbit::ObjectPtr &a,rabbit:
|
|||||||
v->push(a);
|
v->push(a);
|
||||||
v->push(b);
|
v->push(b);
|
||||||
if(SQ_FAILED(sq_call(v, 3, SQTrue, SQFalse))) {
|
if(SQ_FAILED(sq_call(v, 3, SQTrue, SQFalse))) {
|
||||||
if(!sq_isstring( v->_lasterror))
|
if (v->_lasterror.isString() == false) {
|
||||||
v->raise_error("compare func failed");
|
v->raise_error("compare func failed");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(SQ_FAILED(sq_getinteger(v, -1, &ret))) {
|
if(SQ_FAILED(sq_getinteger(v, -1, &ret))) {
|
||||||
|
@ -27,7 +27,7 @@ rabbit::Result rabbit::sq_getfunctioninfo(rabbit::VirtualMachine* v,int64_t leve
|
|||||||
int64_t cssize = v->_callsstacksize;
|
int64_t cssize = v->_callsstacksize;
|
||||||
if (cssize > level) {
|
if (cssize > level) {
|
||||||
rabbit::VirtualMachine::callInfo &ci = v->_callsstack[cssize-level-1];
|
rabbit::VirtualMachine::callInfo &ci = v->_callsstack[cssize-level-1];
|
||||||
if(sq_isclosure(ci._closure)) {
|
if(ci._closure.isClosure()) {
|
||||||
rabbit::Closure *c = ci._closure.toClosure();
|
rabbit::Closure *c = ci._closure.toClosure();
|
||||||
rabbit::FunctionProto *proto = c->_function;
|
rabbit::FunctionProto *proto = c->_function;
|
||||||
fi->funcid = proto;
|
fi->funcid = proto;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user