Explorar el Código

Change blob validation mask and _get method to allow call for default delegate.

mingodad hace 13 años
padre
commit
108b253d0a
Se han modificado 2 ficheros con 17 adiciones y 2 borrados
  1. 9 0
      samples/test-weakref.nut
  2. 8 2
      sqstdlib/sqstdblob.cpp

+ 9 - 0
samples/test-weakref.nut

@@ -0,0 +1,9 @@
+class A {}
+local instA = A();
+print(instA);
+local weakv = instA.weakref();
+print(weakv);
+local instBlob = blob();
+print(instBlob);
+weakv = instBlob.weakref();
+print(weakv);

+ 8 - 2
sqstdlib/sqstdblob.cpp

@@ -207,7 +207,13 @@ static SQInteger _blob__set(HSQUIRRELVM v)
 static SQInteger _blob__get(HSQUIRRELVM v)
 {
 	SETUP_BLOB(v);
-	SQInteger idx;
+	SQInteger idx;
+	SQObjectType ptype = sq_gettype(v, 2);
+	if( !(ptype == OT_INTEGER || ptype == OT_FLOAT) ){
+	    //allow call metatable methods indexed by strings
+	    sq_reseterror(v);
+	    return SQ_ERROR;
+	}
 	sq_getinteger(v,2,&idx);
 	if(idx < 0 || idx >= self->Len())
 		return sq_throwerror(v,_SC("index out of range"));
@@ -328,7 +334,7 @@ static SQRegFunction _blob_methods[] = {
 	_DECL_BLOB_FUNC(swap4,1,_SC("x")),
 	_DECL_BLOB_FUNC(memset,4,_SC("xiii")),
 	_DECL_BLOB_FUNC(_set,3,_SC("xnn")),
-	_DECL_BLOB_FUNC(_get,2,_SC("xn")),
+	_DECL_BLOB_FUNC(_get,2,_SC("x n|s")), //allow call metatable methods indexed by strings
 	_DECL_BLOB_FUNC(_typeof,1,_SC("x")),
 	_DECL_BLOB_FUNC(_nexti,2,_SC("x")),
 	_DECL_BLOB_FUNC(_cloned,2,_SC("xx")),