You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Phil Today at 9:33 AM
Idea: foreign function interface in KRL so that rulesets can use JavaScript modules. Any exported function world be importable. (edited)
👍
1
3 replies
Phil 32 minutes ago
One question would be how the module (and its dependencies) would be loaded into the engine so it’s available.
Phil 31 minutes ago
This would allow mixed programs of KRL and JS and allow KRL programs to make use of existing JS modules without having to modify the engine to load them.
Phil 24 minutes ago
JS imports can be urls. So we could limit modules to only those that load dependencies from urls. But I’m not sure how we do that to arbitrary depth. I guess then it’s the developers problem. We just report that a module can’t be loaded because dependencies can’t be found.
The text was updated successfully, but these errors were encountered:
Currently, we write JS modules (aka libraries) in TypeScript, in the folder pico-engine/packages/pico-engine-core/src/modules and they get transpiled to JS and put into the pico-engine/packages/pico-engine-core/dist/modules folder.
However, that is not the end of the story. It is also necessary to modify pico-engine/packages/pico-engine-core/src/PicoEngineCore.ts to actually import the JS module and make it available to compiled (into JS) KRL rulesets. This commit shows the changes needed for a new JS module.
Things are tricky if the JS module has to have access to the pico engine core. It's a lot simpler if it just stands alone relative to pico things, as in the comment to this commit.
I'm imagining a directive in the meta block of a ruleset like:
use module "URL.js" alias myJSfncs
which would allow function calls like
sum = myJSfncs:add(1,2,3)
In order for the JS module to declare functions callable by the KRL code in the importing ruleset, it will have to import the krl-stdlib as in this line.
The current version of ursa.ts provides an example of how the coding would have to look. Search for the string "krl" to see uses of krl-stdlib.
Phil
Today at 9:33 AM
Idea: foreign function interface in KRL so that rulesets can use JavaScript modules. Any exported function world be importable. (edited)
👍
1
3 replies
Phil
32 minutes ago
One question would be how the module (and its dependencies) would be loaded into the engine so it’s available.
Phil
31 minutes ago
This would allow mixed programs of KRL and JS and allow KRL programs to make use of existing JS modules without having to modify the engine to load them.
Phil
24 minutes ago
JS imports can be urls. So we could limit modules to only those that load dependencies from urls. But I’m not sure how we do that to arbitrary depth. I guess then it’s the developers problem. We just report that a module can’t be loaded because dependencies can’t be found.
The text was updated successfully, but these errors were encountered: