Handling primitive types as objects
BlitzMax Forums/BlitzMax Programming/Handling primitive types as objects
| ||
I need to invoke functions like it is the case with the Reflection module. I had this problem earlier (also asked here in the forums for help), but I didn't find any solution which was satisfying I came up with this: Function InvokeFunction(func:Byte Ptr, args:Object[]) Local Callee:Object(arg0:Object, arg1:Object, arg2:Object, arg3:Object, arg4:Object, .. arg5:Object, arg6:Object, arg7:Object, arg8:Object, arg9:Object) = func args = args[..10] Callee(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]) End Function It works fine with functions with non-primitive-type arguments: InvokeFunction(Print, ["Hello World"]) Of course it unfortunately does not work when the function has for example int or float arguments. Is there a reason why this is not possible with Blitz? (I found workarounds for Java so far). Or is there a better solution to this problem? |
| ||
Byte, Short, Int, Float, Long and Double are not Objects. They are not stored `within` the Object custom-type. And why would they be? The CPU has direct registers which hold values, not pointers to types containing values. You would have to make your own wrapper for each type, like:Type MyInteger Field Integer:Int End Type and pass that instead, somewhat less efficiently. |