# HG changeset patch # User rubidium # Date 1213744593 0 # Node ID 3a11ba88eb7c8bef93b89719a3e107cc4e2f436e # Parent 716595242a1987409b6c7d5aa5e761694715b7e4 (svn r13558) [NoAI] -Codechange: generate an error when you pass a wrong typed value via an array meant for integers to the (C++) API. diff -r 716595242a19 -r 3a11ba88eb7c src/squirrel_helper.hpp --- a/src/squirrel_helper.hpp Tue Jun 17 22:37:09 2008 +0000 +++ b/src/squirrel_helper.hpp Tue Jun 17 23:16:33 2008 +0000 @@ -110,7 +110,8 @@ if (SQ_SUCCEEDED(sq_getinteger(vm, -1, &tmp))) { *data.Append() = (int32)tmp; } else { - // TODO: handle following error properly: "array member is not numeric; ignoring member" + sq_pop(vm, 4); + throw sq_throwerror(vm, _SC("a member of an array used as parameter to a function is not numeric")); } sq_pop(vm, 2); @@ -637,8 +638,13 @@ /* Remove the userdata from the stack */ sq_pop(vm, 1); - /* Delegate it to a template that can handle this specific function */ - return HelperT::SQCall((Tcls *)real_instance, *(Tmethod *)ptr, vm); + try { + /* Delegate it to a template that can handle this specific function */ + return HelperT::SQCall((Tcls *)real_instance, *(Tmethod *)ptr, vm); + } catch (SQInteger e) { + sq_pop(vm, nparam); + return e; + } } /** @@ -693,8 +699,13 @@ /* Get the real function pointer */ sq_getuserdata(vm, nparam, &ptr, 0); - /* Delegate it to a template that can handle this specific function */ - return HelperT::SQCall((Tcls *)NULL, *(Tmethod *)ptr, vm); + try { + /* Delegate it to a template that can handle this specific function */ + return HelperT::SQCall((Tcls *)NULL, *(Tmethod *)ptr, vm); + } catch (SQInteger e) { + sq_pop(vm, nparam); + return e; + } } /** @@ -717,12 +728,20 @@ template inline SQInteger DefSQConstructorCallback(HSQUIRRELVM vm) { - /* Create the real instance */ - Tcls *instance = HelperT::SQConstruct((Tcls *)NULL, (Tmethod)NULL, vm); - sq_setinstanceup(vm, -Tnparam, instance); - sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback); - instance->AddRef(); - return 0; + /* Find the amount of params we got */ + int nparam = sq_gettop(vm); + + try { + /* Create the real instance */ + Tcls *instance = HelperT::SQConstruct((Tcls *)NULL, (Tmethod)NULL, vm); + sq_setinstanceup(vm, -Tnparam, instance); + sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback); + instance->AddRef(); + return 0; + } catch (SQInteger e) { + sq_pop(vm, nparam); + return e; + } } }; // namespace SQConvert