Here is the code for JavaScript using JSON:
Code:
var CEF = {
Callbacks:{/*guid*/}
};
procedure resolveWebGadgetEx(GUID.s, P.s)
ExecuteWebGadgetExJavaScript(PBWebGadgetEx, "CEF.Resolves['" + GUID + "'](" + P + ")", @OutputWebGadgetEx, @ErrorOutputWebGadgetEx)
endProcedure
CEF.call = (fun, arg={}) => { // async call -> return value via resolve used
let R = new Promise((resolve, reject) => {
arg.GUID = JS.guid()
CEF.Resolves[arg.GUID] = resolve
PB.call.call(null, fun, JSON.stringify(arg))
});
return R
};
CEF.callS = (fun, arg) => { // sync call -> no return value used
PB.call.call(null, fun, JSON.stringify(arg))
};
Here the PureBasic code to handle this (example with LibXL):
Code:
structure ArgWebGadgetEx
GUID .s
endStructure
structure saveExcelWorkbookArgWG extends ArgWebGadgetEx
WB .i
FilePath .s
endStructure
procedure saveExcelWorkbookWG(*P)
var P.s = PeekS(*P)
var J = ParseJSON(#PB_Any, P)
var Arg.saveExcelWorkbookArgWG
ExtractJSONStructure(JSONValue(J), @Arg, saveExcelWorkbookArgWG)
var R = bool(saveExcelWorkbook(Arg\WB, Arg\FilePath) = 0)
resolveWebGadgetEx(Arg\GUID, Str(R))
endProcedure
So, using it in JS could be done this way:
Code:
async free(){
CEF.callS('freeExcelWorkbook', {WB:this.Nr}) // no return value needed...
}
async save(FilePath){
return await CEF.call('saveExcelWorkbook', {WB:this.Nr, FilePath})
}