Re: Replace external functions/commands with JS
Posted: Fri Jan 20, 2023 4:47 am
LC has to be the tool, because the app being deployed to HTML5 is a very extensive GUI codebase written in LC and used on desktop.stam wrote: ↑Wed Jan 18, 2023 3:14 amI wasn't asking what javascript method you're trying to replicate in LC. I was asking what the overall intention of what you're doing is - because if you think LiveCode is a good fit for whatever it is you're doing, then maybe there is a better LiveCode way of doing it. If not, then perhaps LC is the wrong tool for the job.
Several things. One is to use a JavaScript client for large OpenAPI, which is autogenerated from the spec via an OpenAPI generator. There is no LCScript generator for OpenAPI (google "list of openapi generators", I can't post the link), and writing one is a very laborious undertaking. Manually writing LCScript client functions would be laborious and error-prone, and they'd quickly fall outdated (as the APIs are updated regularly updated). So I'd like to call autogenerated ones, necessitating JS.
The issue with calling stateful JS code would be that the state comes from JS, either a JS object or a context, which as noted above will not survive stringification. LCScript can only call JS via "do as javascript", which only returns strings. That's a limitation, but I believe I can call this JS code statelessly (for now). The issue that currently blocks me is that the JS calls are asynchronous (they return via a callback or Promise).
How could "script variables" or "send in time" synchronize a "do as javascript" that does not return a value, but merely causes a JS callback to be executed in the JS environment some time later? AFAICT they can't.
Do you want an explicit example? I'm calling a JS function like one of these:
Code: Select all
function returnsImmediately (argFoo, argBar, callbackFunction) { ... }
async function returnsPromise (argFoo, argBar) { ... }
Code: Select all
do "JSON->stringify(someSyncFunction(" & argFoo & "," & argBar & ))" as "javascript"
put JsonImport(result()) into myVar