Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Compiler/src/lcode.cpp
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#include "luacode.h"
3
4
#include "Luau/Compiler.h"
5
6
#include <string.h>
7
8
char* luau_compile(const char* source, size_t size, lua_CompileOptions* options, size_t* outsize)
9
{
10
LUAU_ASSERT(outsize);
11
12
Luau::CompileOptions opts;
13
14
if (options)
15
{
16
static_assert(sizeof(lua_CompileOptions) == sizeof(Luau::CompileOptions), "C and C++ interface must match");
17
memcpy(static_cast<void*>(&opts), options, sizeof(opts));
18
}
19
20
std::string result = compile(std::string(source, size), opts);
21
22
char* copy = static_cast<char*>(malloc(result.size()));
23
if (!copy)
24
return nullptr;
25
26
memcpy(copy, result.data(), result.size());
27
*outsize = result.size();
28
return copy;
29
}
30
31
void luau_set_compile_constant_nil(lua_CompileConstant* constant)
32
{
33
Luau::setCompileConstantNil(constant);
34
}
35
36
void luau_set_compile_constant_boolean(lua_CompileConstant* constant, int b)
37
{
38
Luau::setCompileConstantBoolean(constant, b != 0);
39
}
40
41
void luau_set_compile_constant_number(lua_CompileConstant* constant, double n)
42
{
43
Luau::setCompileConstantNumber(constant, n);
44
}
45
46
void luau_set_compile_constant_integer64(lua_CompileConstant* constant, int64_t l)
47
{
48
Luau::setCompileConstantInteger64(constant, l);
49
}
50
51
void luau_set_compile_constant_vector(lua_CompileConstant* constant, float x, float y, float z, float w)
52
{
53
Luau::setCompileConstantVector(constant, x, y, z, w);
54
}
55
56
void luau_set_compile_constant_string(lua_CompileConstant* constant, const char* s, size_t l)
57
{
58
Luau::setCompileConstantString(constant, s, l);
59
}
60
61