-
Notifications
You must be signed in to change notification settings - Fork 5
/
luau_binding_generator.py
63 lines (44 loc) · 1.61 KB
/
luau_binding_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Mirrors a lot of what the godot-cpp binder does.
# Some code is similar or the same.
import json
from pathlib import Path
from bindgen.stack_ops import generate_stack_ops
from bindgen.api_bin import generate_api_bin
from bindgen.typedefs import generate_typedefs
import platform
major, minor, patch = platform.python_version_tuple()
if int(major) > 3 or (int(major) == 3 and int(minor) >= 11):
import tomllib
else:
import tomli as tomllib
def scons_emit_files(target, source, env):
files = [
# Stack
env.File("gen/include/core/builtins_stack.gen.inc"),
env.File("gen/src/builtins_stack.gen.cpp"),
# Extension API
env.File("gen/src/extension_api_bin.gen.cpp")
]
env.Clean(files, target)
return target + files, source
def scons_generate_bindings(target, source, env):
output_dir = target[0].abspath
# Open API
api = None
with open(str(source[0])) as api_file:
api = json.load(api_file)
# Open class settings
class_settings = {}
with open(str(source[1]), "rb") as settings_file:
class_settings = tomllib.load(settings_file)
# Initialize output folders
src_dir = Path(output_dir) / "gen" / "src"
src_dir.mkdir(parents=True, exist_ok=True)
include_dir = Path(output_dir) / "gen" / "include"
include_dir.mkdir(parents=True, exist_ok=True)
defs_dir = Path(output_dir) / "definitions"
# Codegen
generate_stack_ops(src_dir, include_dir, api)
generate_api_bin(src_dir, api, class_settings)
generate_typedefs(defs_dir, api, class_settings, str(source[2]), str(source[3]))
return None