How to actually embed Luau? #1214
-
Hi there! I've been trying for the past 3 days to figure out how to properly embed Luau (in a similar manner to how Lua is embedded) but I just can't quite figure it out. If someone could provide some basic instructions on what to include, and perhaps a basic example showing how to load and run a lua script from a file, that would be immensely appreciated! Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The answer kind of depends on what you need out of the embedding (especially if you, e.g., want to use the type checker as well), but we have the same headers as Lua available with the same API. If you want to use that, I believe you should only need to include the VM and the compiler. #include "lua.h"
#include "lualib.h" If you want to see more thorough usage examples that include also using some of Luau's C++ APIs, I'd recommend looking at the CLI folder which contains, essentially, a bunch of standalone programs that embed and use Luau: https://github.com/luau-lang/luau/tree/master/CLI |
Beta Was this translation helpful? Give feedback.
If the only thing you care about is invoking Luau code, this is answered already in the README under the heading
Building
. You can find that here.At which point, you have loaded the code, and you can use
lua_resume
to initiate execution. I recommend looking at Repl.cpp for a more full-fledged example, but as far as I know, embedding should proceed more-or-less the same as Lua 5.1 besides compiling separately.