in SpiderBasic the loading of data must be realized with a callback and I need a hint how to pass a structure variable to the loading callback within a module.
I work on a module which works with AllocateStructur() and each procedure of the module gets the address of the allocated structure passed by the caller.
This is also the case with the planned JSON load function. My problem is, that inside the CallBack procedure the adress of the structure, which is needed to process the JSON file, is not known. I would have to pass it to the CallBack function, but I don't know how to do that.
I do not want to use a temporary global variable inside the module, because this can lead to data errors, if the load function is called several times from different callers.
In Purebasic the whole thing is just a "two-liner" which does not cause any problems:
Code: Select all
; PureBasic
LoadJSON(0, "mystuff.json")
ExtractJSONStructure(JSONValue(0), *StructPointer, myStruct)
Code: Select all
Procedure LoadOk(iType.i, sFilename.s, iObjectId.i)
If iType = #PB_Loading_JSON
Debug "JSON Loaded"
Debug sFilename
Debug iObjectId
ExtractJSONStructure(JSONValue(iObjectId), *StructPointer, myStruct)
EndIf
EndProcedure
Procedure LoadError(iType.i, sFilename.s, iObjectId.i)
If iType = #PB_Loading_JSON
Debug "JSON Loading Error"
Debug sFilename
Debug iObjectId
EndIf
EndProcedure
Procedure.i LoadStuff(*StructPointer.myStruct, sFilename.s)
If *StructPointer <> 0
BindEvent(#PB_Event_Loading, @LoadOk())
BindEvent(#PB_Event_LoadingError, @LoadError())
ProcedureReturn LoadJSON(#PB_Any, sFilename)
EndIf
EndProcedure
Many thanks for your tips.
Markus