Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Compiler/include/luacode.h
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include <stddef.h>
5
#include <stdint.h>
6
7
// can be used to reconfigure visibility/exports for public APIs
8
#ifndef LUACODE_API
9
#define LUACODE_API extern
10
#endif
11
12
typedef struct lua_CompileOptions lua_CompileOptions;
13
typedef void* lua_CompileConstant;
14
15
// return a type identifier for a global library member
16
// values are defined by 'enum LuauBytecodeType' in Bytecode.h
17
typedef int (*lua_LibraryMemberTypeCallback)(const char* library, const char* member);
18
19
// setup a value of a constant for a global library member
20
// use luau_set_compile_constant_*** set of functions for values
21
typedef void (*lua_LibraryMemberConstantCallback)(const char* library, const char* member, lua_CompileConstant* constant);
22
23
struct lua_CompileOptions
24
{
25
// 0 - no optimization
26
// 1 - baseline optimization level that doesn't prevent debuggability
27
// 2 - includes optimizations that harm debuggability such as inlining
28
int optimizationLevel; // default=1
29
30
// 0 - no debugging support
31
// 1 - line info & function names only; sufficient for backtraces
32
// 2 - full debug info with local & upvalue names; necessary for debugger
33
int debugLevel; // default=1
34
35
// type information is used to guide native code generation decisions
36
// information includes testable types for function arguments, locals, upvalues and some temporaries
37
// 0 - generate for native modules
38
// 1 - generate for all modules
39
int typeInfoLevel; // default=0
40
41
// 0 - no code coverage support
42
// 1 - statement coverage
43
// 2 - statement and expression coverage (verbose)
44
int coverageLevel; // default=0
45
46
// alternative global builtin to construct vectors, in addition to default builtin 'vector.create'
47
const char* vectorLib;
48
const char* vectorCtor;
49
50
// alternative vector type name for type tables, in addition to default type 'vector'
51
const char* vectorType;
52
53
// null-terminated array of globals that are mutable; disables the import optimization for fields accessed through these
54
const char* const* mutableGlobals;
55
56
// null-terminated array of userdata types that will be included in the type information
57
const char* const* userdataTypes;
58
59
// null-terminated array of globals which act as libraries and have members with known type and/or constant value
60
// when an import of one of these libraries is accessed, callbacks below will be called to receive that information
61
const char* const* librariesWithKnownMembers;
62
lua_LibraryMemberTypeCallback libraryMemberTypeCb;
63
lua_LibraryMemberConstantCallback libraryMemberConstantCb;
64
65
// null-terminated array of library functions that should not be compiled into a built-in fastcall ("name" "lib.name")
66
const char* const* disabledBuiltins;
67
};
68
69
// compile source to bytecode; when source compilation fails, the resulting bytecode contains the encoded error. use free() to destroy
70
LUACODE_API char* luau_compile(const char* source, size_t size, lua_CompileOptions* options, size_t* outsize);
71
72
// when libraryMemberConstantCb is called, these methods can be used to set a value of the opaque lua_CompileConstant struct
73
// vector component 'w' is not visible to VM runtime configured with LUA_VECTOR_SIZE == 3, but can affect constant folding during compilation
74
// string storage must outlive the invocation of 'luau_compile' which used the callback
75
LUACODE_API void luau_set_compile_constant_nil(lua_CompileConstant* constant);
76
LUACODE_API void luau_set_compile_constant_boolean(lua_CompileConstant* constant, int b);
77
LUACODE_API void luau_set_compile_constant_number(lua_CompileConstant* constant, double n);
78
LUACODE_API void luau_set_compile_constant_integer64(lua_CompileConstant* constant, int64_t l);
79
LUACODE_API void luau_set_compile_constant_vector(lua_CompileConstant* constant, float x, float y, float z, float w);
80
LUACODE_API void luau_set_compile_constant_string(lua_CompileConstant* constant, const char* s, size_t l);
81
82