mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
Update README.md
Switch to luau_compile and specify env for luau_load
This commit is contained in:
parent
3f1508c83a
commit
100710c9f6
1 changed files with 7 additions and 2 deletions
|
@ -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:
|
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
|
```cpp
|
||||||
std::string bytecode = Luau::compile(source); // needs Luau/Compiler.h include
|
// needs lua.h and luacode.h
|
||||||
if (luau_load(L, chunkname, bytecode.data(), bytecode.size()) == 0)
|
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 */
|
return 1; /* return chunk main function */
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue