yoshiask / CopticChanter

2 stars 0 forks source link

Allow for compiled scripts #12

Open yoshiask opened 11 months ago

yoshiask commented 11 months ago

One of the biggest hits to performance when displaying content is executing scripts. Some languages are faster than others (so far, Lua is the fastest and C# is the slowest), but in theory any language can be optimized by compiling it into some form of bytecode.

Lua would be relatively simple to implement, since .luac is a standard format that NLua supports. C# can also be compiled down to IL, though it may require external tools such as the .NET SDK. However, the bigger problem would be executing the compiled code: several platforms restrict runtime code generation or loading of native/external libraries (e.g. NLua can't P/Invoke KeraLua at all on WASM, UWP and iOS can't load assemblies at runtime).

One potential solution would be to use entirely managed interpreters, which may be accomplished using MoonSharp or WattleScript for Lua but would be nearly impossible for C#. For very simple instructions, such as the return dayOfWeek() + 2; Lua script used by the Midnight Praises sequence to determine which Theotokia to show, a custom basic Assembly language may be designed.