2023-08-10 20:38:25 +01:00
|
|
|
--[=[
|
|
|
|
@interface CompileOptions
|
|
|
|
@within Luau
|
|
|
|
|
|
|
|
The Luau compiler options used in generating luau bytecode
|
|
|
|
|
|
|
|
This is a dictionary that may contain one or more of the following values:
|
|
|
|
|
|
|
|
* `optimizationLevel` - Sets the compiler option "optimizationLevel". Defaults to `1`
|
|
|
|
* `coverageLevel` - Sets the compiler option "coverageLevel". Defaults to `0`
|
|
|
|
* `debugLevel` - Sets the compiler option "debugLevel". Defaults to `1`
|
|
|
|
|
|
|
|
Documentation regarding what these values represent can be found here;
|
|
|
|
* https://github.com/Roblox/luau/blob/bd229816c0a82a8590395416c81c333087f541fd/Compiler/include/luacode.h#L13
|
|
|
|
]=]
|
|
|
|
export type CompileOptions = {
|
2023-10-04 03:11:21 +01:00
|
|
|
optimizationLevel: number?,
|
|
|
|
coverageLevel: number?,
|
|
|
|
debugLevel: number?,
|
2023-08-10 20:38:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
--[=[
|
|
|
|
@interface LoadOptions
|
|
|
|
@within Luau
|
|
|
|
|
|
|
|
The Luau load options are used for generating a lua function from either bytecode or sourcecode
|
|
|
|
|
|
|
|
This is a dictionary that may contain one or more of the following values:
|
|
|
|
|
2023-10-04 03:03:47 +01:00
|
|
|
* `debugName` - The debug name of the closure. Defaults to `luau.load(...)`
|
|
|
|
* `environment` - Environment values to set and/or override. Includes default globals unless overwritten.
|
2023-08-10 20:38:25 +01:00
|
|
|
]=]
|
|
|
|
export type LoadOptions = {
|
2023-10-04 03:03:47 +01:00
|
|
|
debugName: string?,
|
|
|
|
environment: { [string]: any }?,
|
2023-08-10 20:38:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
--[=[
|
|
|
|
@class Luau
|
|
|
|
|
|
|
|
Built-in library for generating luau bytecode & functions.
|
|
|
|
|
|
|
|
### Example usage
|
|
|
|
|
|
|
|
```lua
|
|
|
|
local luau = require("@lune/luau")
|
|
|
|
|
|
|
|
local bytecode = luau.compile("print('Hello, World!')")
|
|
|
|
local callableFn = luau.load(bytecode)
|
|
|
|
|
|
|
|
-- Additionally, we can skip the bytecode generation and load a callable function directly from the code itself.
|
|
|
|
-- local callableFn = luau.load("print('Hello, World!')")
|
|
|
|
|
|
|
|
callableFn()
|
|
|
|
```
|
|
|
|
]=]
|
|
|
|
local luau = {}
|
|
|
|
|
|
|
|
--[=[
|
|
|
|
@within Luau
|
|
|
|
|
|
|
|
Compiles sourcecode into Luau bytecode
|
|
|
|
|
|
|
|
An error will be thrown if the sourcecode given isn't valid Luau code.
|
|
|
|
|
|
|
|
### Example usage
|
|
|
|
|
|
|
|
```lua
|
|
|
|
local luau = require("@lune/luau")
|
|
|
|
|
|
|
|
local bytecode = luau.compile("print('Hello, World!')", {
|
|
|
|
optimizationLevel: 1,
|
|
|
|
coverageLevel: 0,
|
|
|
|
debugLevel: 1,
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
@param source The string that'll be compiled into bytecode
|
2023-08-26 22:22:49 +01:00
|
|
|
@param compileOptions The luau compiler options used when compiling the source string
|
2023-08-10 20:38:25 +01:00
|
|
|
|
|
|
|
@return luau bytecode
|
|
|
|
]=]
|
2023-08-26 22:22:49 +01:00
|
|
|
function luau.compile(source: string, compileOptions: CompileOptions?): string
|
2023-08-10 20:38:25 +01:00
|
|
|
return nil :: any
|
|
|
|
end
|
|
|
|
|
|
|
|
--[=[
|
|
|
|
@within Luau
|
|
|
|
|
|
|
|
Generates a function from either bytecode or sourcecode
|
|
|
|
|
|
|
|
An error will be thrown if the sourcecode given isn't valid luau code.
|
|
|
|
|
|
|
|
### Example usage
|
|
|
|
|
|
|
|
```lua
|
|
|
|
local luau = require("@lune/luau")
|
|
|
|
|
|
|
|
local bytecode = luau.compile("print('Hello, World!')")
|
|
|
|
local callableFn = luau.load(bytecode, {
|
|
|
|
debugName = "'Hello, World'"
|
|
|
|
})
|
|
|
|
|
|
|
|
callableFn()
|
|
|
|
```
|
|
|
|
|
|
|
|
@param source Either bytecode or sourcecode
|
|
|
|
@param loadOptions The load options used when creating a callbable function
|
|
|
|
|
|
|
|
@return luau function
|
|
|
|
]=]
|
2023-08-12 01:17:48 +01:00
|
|
|
function luau.load(source: string, loadOptions: LoadOptions?): (...any) -> ...any
|
2023-08-10 20:38:25 +01:00
|
|
|
return nil :: any
|
|
|
|
end
|
|
|
|
|
|
|
|
return luau
|