Skip to content

How to actually embed Luau? #1214

Answered by aatxe
Nolram12345 asked this question in Q&A
Mar 26, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

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.

// needs lua.h and luacode.h
lua_State* L = luaL_newstate();

size_t bytecodeSize = 0;
char* bytecode = luau_compile(source, strlen(source), NULL, &bytecodeSize);
int result = luau_load(L, chunkname, bytecode, bytecodeSize, 0);
free(bytecode);

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.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Nolram12345
Comment options

@aatxe
Comment options

Answer selected by Nolram12345
@Nolram12345
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants