makspll / bevy_mod_scripting

Bevy Scripting Plugin
Apache License 2.0
390 stars 31 forks source link

Support for pre-processing #110

Open makspll opened 5 months ago

makspll commented 5 months ago

There is a large family of languages that transpile to Lua, Teal and Fennel being some of them.

Right now supporting a new transpiled language still likely requires creating a whole new ScriptHost and AssetLoader, what If we instead allowed users to "hook" into the existing asset loader and allow other extensions to be loaded to the same asset?

Are the bevy asset preprocessor flows a good choice for this?

knutsoned commented 5 months ago

As an example, I started working on a Fennel mod that tries to set up a dedicated Lua context for transpiling inside the AssetReader, then hands off the Lua source to the standard LuaScriptHost in the usual way:

https://github.com/knutsoned/bevy_mod_scripting_fennel

Note: Since the Fennel compiler is just a Lua module, I'm loading its source from a large string and using lazy_static so I only need to do that once. So far this works to load the Fennel source and execute inline functions. There seems to be a bug calling modules defined in the Fennel at the moment.

Assuming the issue can be resolved, this may be a good testbed to try a version where we use a preprocessor. This may also be the right place to note it would be good to be able to AoT compile Fennel for packaging. Ideally, the runtime compiler would be used during dev, and the Fennel source would be precompiled to Lua during a release build, inlined, and loaded directly by a released binary.