bmx-ng / brl.mod

BlitzMax Runtime Libraries, for BlitzMax NG.
12 stars 12 forks source link

[brl.reflection] invoke trouble #204

Open GWRon opened 3 years ago

GWRon commented 3 years ago
Type TSavegameConverter
    Function GetCurrentFieldName:Object(fieldName:String, parentTypeName:String)
        Select (parentTypeName+":"+fieldName).ToLower()
            case "TIngameHelpWindowCollection:disabledHelpGUIDs".ToLower()
                'could return new field name for it now
                Return new TStringWrap("disabledHelpGUIDsNEW")
        End Select
        Return new TStringWrap(fieldName)
    End Function
...

So it returns a type (which has "Field value:String = the value").

Now I try to evaluate the results via an "TFunction.invoke()" call:

        local f:TFunction  = converterTypeID.FindFunction("GetCurrentFieldName")
        If not f Then Throw "Unknown function. Create function ~qGetCurrentFieldName:Object(fieldName:String, parentTypeName:String)~q in type ~q" + converterTypeID.name() +"~q."

        'return null or the new field name
        local newFieldNameObj:object = f.Invoke([object(fieldName), object(parentTypeName)])
        print "received: " + TTypeID.ForObject(newfieldNameObj).name()

it prints "received: string"

The original issue is, that I return strings (which should be possible) but when printing the results, I get "numbers". As if it returns the "bytes", not the actual string.

GWRon commented 3 years ago

So you might have spotted, that I used "fieldName:STRING" and "parentTypeName:STRING" as parameters in the definition ... while it might have to be "objects". But still the received invoke result when returning "disabledHelpGUIDsNEW" is "13930288" - not the string I wanted.

GWRon commented 3 years ago

If I used a "method" instead of the function, everything works (also with ":string" parameters)

So I assume the "function invokation" has issues here.

HurryStarfish commented 3 years ago

Is this on the _reflect branches or on master?

GWRon commented 3 years ago

This is on master ... which I use as others compile my stuff too and I cannot expect them to use "different than master" branches.