I am looking for a game script lang. I know what I am doing. I used to bind some lang like lua/python into c++/c# host game. So please don’t try explain why I should not do such thing. I want try something new/weird. Just tell me is there a way compile zig system into dynamic library, so I can call it to load zig script, transform data between zig and it’s host just like a script lang.
Any help or doc link would be nice, thanks.
Zig is not a scripting language (you may get it wrong because of zig run
, in fact it compiles your code and places resulting executable in cache directory to run it), you can’t load and call it like you do with traditional script runtimes.
But something like this is possible. You can compile your “scripts” as a shared library (.dll
/.so
) and load resulting object at runtime. If you setup cache system for these scripts (as individual compilation of a single script would take a while) it could even work as (ugly) real-world solution. You don’t need to wrap Zig build system in dynamic library for that, but if you still up to it, exporting main.buildOutputType
should be enough to build shared libraries.
I know this way. But it is not what I want.
In some platform, like mobile ios of apple, downloading dll and reloading it was forbidden. And I want to focus on mobile platform.
Thanks for reply.
You can also utilize Wasm for this. Wasm runtimes can be run without dynamic native code loading, so this would fit into your constraints.
I think @yanfeigame is looking for a scripting language that is easy to embed within a Zig application, I think some of the languages listed here fit that criteria (but I haven’t really tried them so you need to check yourself):
Specifically I think these may work (and seem active):
- GitHub - fubark/cyber: Fast and concurrent scripting.
- GitHub - ikskuh/LoLa: LoLa is a small programming language meant to be embedded into games.
- GitHub - sin-ack/zigself: An implementation of the Self programming language in Zig
There is also:
- GitHub - natecraddock/ziglua: Zig bindings for the Lua C API
In case you want to use lua again.
Thanks for let me know zig could build script into wasm. It would be a fallback choice, if nothing else I can do, it seems I have to take this way.
Thanks for reply. I need zig itself be compiled into dynamic library, be a script lang. I will check the link you post in case the lands beyond my excepting.