I'm using thinBasic as the macro engine for my app (SPFLite) and it works just fine. But I'm trying to pass a UDT from the macro code to a function in SPFLite. Both the macro and SPFLite code are using compatible TYPE definitions. But I can't seem to establish a pointer in the SPFLite code to the UDT area in the thinBasic macro.
Here's the thinBasic macro:
' Try.macro
SPF_Trace(Off)
SPF_CMD("CLS")
type ENVType
ID as string * 2
Num as long
Txt as asciiz * 100
end type
dim ENV as ENVType
ENV.ID = "XY"
ENV.Num = 789
ENV.Txt = "AAAAA"
SPF_Try(ENV)
spf_Debug(ENV.Num)
spf_Debug(ENV.Txt)
Halt (OK)
And here's my attempt at the function:
FUNCTION SPF_Try() AS LONG '
'--------------------------------------------------------------------------------------------------+
'- Try stuff |
'--------------------------------------------------------------------------------------------------+
LOCAL UDTName, lTxt() AS STRING '
LOCAL i, pVar, lMainType, lSubType, lIsArray, pDirect, ArrayElements, ArrayPtr, lSize, lCounter AS LONG '
LOCAL aText AS WSTRING
#ALIGN 4
LOCAL pENV AS ENVType PTR ' Map the passed area
LOCAL pRaw AS BYTE PTR ' Temp for step over
IF thinBasic_CheckOpenParens(%True, %True) THEN ' An Open (
UDTName = thinBasic_GetTokenName ' Get next token name as a string
IF thinBasic_CheckCloseParens THEN ' Closed properly?
pVar = thinBasic_VariableGetInfo(UDTName, lMainType, lSubType, lIsArray) ' Get a ptr to a variable (name is ArrayName)
IF pVar <> %Null THEN ' If we get pointer then variable exists
pRaw = thinBasic_VariablePtrToDirectPtr(pVar) ' We need to convert ptr inside parser to pointer inside thinBasic Core
' pRaw += 4
pENV = pRaw
IF @pENV.ID <> "XY" THEN ' Is eyeball correct
'
END IF
@pENV.Num = 123 ' Stuff in some test values
@pENV.Txt = "Hello Sailor" '
ELSE '
thinBasic_RunTimeError(%ERR__VARIABLE_NOT_DEFINED) '
END IF ' End IF pVar
END IF ' End Close )
END IF ' End Open (
FUNCTION = 0: TP.ErrMsgReset '
END FUNCTION '
Looking for suggestions
George