// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details1#pragma once23#include <stddef.h>4#include <stdint.h>56// can be used to reconfigure visibility/exports for public APIs7#ifndef LUACODE_API8#define LUACODE_API extern9#endif1011typedef struct lua_CompileOptions lua_CompileOptions;12typedef void* lua_CompileConstant;1314// return a type identifier for a global library member15// values are defined by 'enum LuauBytecodeType' in Bytecode.h16typedef int (*lua_LibraryMemberTypeCallback)(const char* library, const char* member);1718// setup a value of a constant for a global library member19// use luau_set_compile_constant_*** set of functions for values20typedef void (*lua_LibraryMemberConstantCallback)(const char* library, const char* member, lua_CompileConstant* constant);2122struct lua_CompileOptions23{24// 0 - no optimization25// 1 - baseline optimization level that doesn't prevent debuggability26// 2 - includes optimizations that harm debuggability such as inlining27int optimizationLevel; // default=12829// 0 - no debugging support30// 1 - line info & function names only; sufficient for backtraces31// 2 - full debug info with local & upvalue names; necessary for debugger32int debugLevel; // default=13334// type information is used to guide native code generation decisions35// information includes testable types for function arguments, locals, upvalues and some temporaries36// 0 - generate for native modules37// 1 - generate for all modules38int typeInfoLevel; // default=03940// 0 - no code coverage support41// 1 - statement coverage42// 2 - statement and expression coverage (verbose)43int coverageLevel; // default=04445// alternative global builtin to construct vectors, in addition to default builtin 'vector.create'46const char* vectorLib;47const char* vectorCtor;4849// alternative vector type name for type tables, in addition to default type 'vector'50const char* vectorType;5152// null-terminated array of globals that are mutable; disables the import optimization for fields accessed through these53const char* const* mutableGlobals;5455// null-terminated array of userdata types that will be included in the type information56const char* const* userdataTypes;5758// null-terminated array of globals which act as libraries and have members with known type and/or constant value59// when an import of one of these libraries is accessed, callbacks below will be called to receive that information60const char* const* librariesWithKnownMembers;61lua_LibraryMemberTypeCallback libraryMemberTypeCb;62lua_LibraryMemberConstantCallback libraryMemberConstantCb;6364// null-terminated array of library functions that should not be compiled into a built-in fastcall ("name" "lib.name")65const char* const* disabledBuiltins;66};6768// compile source to bytecode; when source compilation fails, the resulting bytecode contains the encoded error. use free() to destroy69LUACODE_API char* luau_compile(const char* source, size_t size, lua_CompileOptions* options, size_t* outsize);7071// when libraryMemberConstantCb is called, these methods can be used to set a value of the opaque lua_CompileConstant struct72// vector component 'w' is not visible to VM runtime configured with LUA_VECTOR_SIZE == 3, but can affect constant folding during compilation73// string storage must outlive the invocation of 'luau_compile' which used the callback74LUACODE_API void luau_set_compile_constant_nil(lua_CompileConstant* constant);75LUACODE_API void luau_set_compile_constant_boolean(lua_CompileConstant* constant, int b);76LUACODE_API void luau_set_compile_constant_number(lua_CompileConstant* constant, double n);77LUACODE_API void luau_set_compile_constant_integer64(lua_CompileConstant* constant, int64_t l);78LUACODE_API void luau_set_compile_constant_vector(lua_CompileConstant* constant, float x, float y, float z, float w);79LUACODE_API void luau_set_compile_constant_string(lua_CompileConstant* constant, const char* s, size_t l);808182