Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Switch to luau_compile and specify env for luau_load
  • Loading branch information
zeux committed Nov 19, 2021
1 parent 3f1508c commit 100710c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ make config=release luau luau-analyze
To integrate Luau into your CMake application projects, at the minimum you'll need to depend on `Luau.Compiler` and `Luau.VM` projects. From there you need to create a new Luau state (using Lua 5.x API such as `lua_newstate`), compile source to bytecode and load it into the VM like this:

```cpp
std::string bytecode = Luau::compile(source); // needs Luau/Compiler.h include
if (luau_load(L, chunkname, bytecode.data(), bytecode.size()) == 0)
// needs lua.h and luacode.h
size_t bytecodeSize = 0;
char* bytecode = luau_compile(source, strlen(source), NULL, &bytecodeSize);
int result = luau_load(L, chunkname, bytecode, bytecodeSize, 0);
free(bytecode);

if (result == 0)
return 1; /* return chunk main function */
```
Expand Down

0 comments on commit 100710c

Please sign in to comment.