diff --git a/SConstruct b/SConstruct
index 62c61688..f944f63a 100644
--- a/SConstruct
+++ b/SConstruct
@@ -9,9 +9,14 @@ env.tools=['mingw']
env.Append(CPPDEFINES = ['LAPI_GDEXTENSION'])
env.Append(CPPPATH = [Dir('src').abspath, Dir('external').abspath])
+env['sources'] = []
+Export('env')
+SConscript("lua_libraries/SConscript")
+
sources = Glob('*.cpp')
sources.append(Glob('src/*.cpp'))
sources.append(Glob('src/classes/*.cpp'))
+sources.append(env['sources'])
if env["luaapi_luaver"] == 'jit':
env.Append(CPPDEFINES=['LAPI_LUAJIT'])
diff --git a/SCsub b/SCsub
index b35f5e90..41a61235 100644
--- a/SCsub
+++ b/SCsub
@@ -18,6 +18,7 @@ if env["luaapi_luaver"] == "jit" and env['platform']=='javascript':
Export('env_lua')
SConscript('external/SCsub')
+SConscript('lua_libraries/SCsub')
if env["luaapi_luaver"] == 'jit':
env_lua.Append(CPPDEFINES=['LAPI_LUAJIT'])
diff --git a/doc_classes/LuaAPI.xml b/doc_classes/LuaAPI.xml
index 3fb84801..379309b8 100644
--- a/doc_classes/LuaAPI.xml
+++ b/doc_classes/LuaAPI.xml
@@ -22,10 +22,11 @@
-
+
Bind lua libraries to the LuaAPI Object.
+ Returns an error if a library fails to bind.
Note: in C#, the param Array must be a [code]Godot.Collections.Array[/code] and not a [code]System.Array[/code] class.
diff --git a/external/SCsub b/external/SCsub
index 26d1a54a..4eb63027 100644
--- a/external/SCsub
+++ b/external/SCsub
@@ -1,4 +1,3 @@
-
Import('env')
Import('env_lua')
@@ -74,6 +73,7 @@ if luaver == "jit":
else:
env.Append(LIBPATH=[Dir("luaJIT/src").abspath])
env.Append(LIBS=['libluajit'])
+ env_lua.Append(CPPPATH=[Dir('luaJIT/src').abspath])
elif luaver == "5.1":
env_lua.Append(CPPDEFINES='MAKE_LIB')
@@ -87,7 +87,8 @@ elif luaver == "5.1":
env_lua['CFLAGS'].remove('-std=gnu11')
env_lua.Append(CFLAGS=['-std=c99'])
- env_lua.add_source_files(env.modules_sources,'lua/*.c')
+ env_lua.Append(CPPPATH=[Dir('lua51').abspath])
+ env_lua.add_source_files(env.modules_sources,'lua51/*.c')
else:
env_lua.Append(CPPDEFINES='MAKE_LIB')
@@ -101,5 +102,6 @@ else:
env_lua['CFLAGS'].remove('-std=gnu11')
env_lua.Append(CFLAGS=['-std=c99'])
- env_lua.add_source_files(env.modules_sources,'lua/onelua.c')
+ env_lua.Append(CPPPATH=[Dir('lua').abspath])
+ env_lua.add_source_files(env.modules_sources, 'lua/onelua.c')
diff --git a/lua_libraries/.gitignore b/lua_libraries/.gitignore
new file mode 100644
index 00000000..7611336c
--- /dev/null
+++ b/lua_libraries/.gitignore
@@ -0,0 +1,9 @@
+*
+
+!.gitignore
+!SCsub
+!SConscript
+!codegen.py
+!codegen.py
+!README.md
+!lua_libraries.h
\ No newline at end of file
diff --git a/lua_libraries/README.md b/lua_libraries/README.md
new file mode 100644
index 00000000..90896888
--- /dev/null
+++ b/lua_libraries/README.md
@@ -0,0 +1,8 @@
+## Lua Libraries
+This is a code gen module which allows you to statically compile a lua C library into this addon. Its as simple as downloading the source for the addon, and adding it as a folder with the library name in this folder.
+
+It is important that the folder name be exactly the library name in lowercase. No version numbers included.
+
+The code gen will auto detect it next time you build the addon. Either as a module or for GDExtension.
+
+This is very new and potentially very prone to failure. So for lpeg has been tested and confirmed to work.
\ No newline at end of file
diff --git a/lua_libraries/SConscript b/lua_libraries/SConscript
new file mode 100644
index 00000000..82e1b668
--- /dev/null
+++ b/lua_libraries/SConscript
@@ -0,0 +1,10 @@
+Import('env')
+from codegen import code_gen
+
+code_gen(env['luaapi_luaver'] == 'jit')
+
+sources = ['lua_libraries.gen.cpp']
+library_name = "liblualibraries{}{}".format(env['suffix'], env["LIBSUFFIX"])
+
+env.Append(sources=["lua_libraries/lua_libraries.gen.cpp"])
+env.Append(CPPPATH=[Dir('.').abspath])
\ No newline at end of file
diff --git a/lua_libraries/SCsub b/lua_libraries/SCsub
new file mode 100644
index 00000000..de234c1e
--- /dev/null
+++ b/lua_libraries/SCsub
@@ -0,0 +1,9 @@
+Import('env')
+Import('env_lua')
+
+from codegen import code_gen
+
+code_gen(env['luaapi_luaver'] == 'jit')
+
+env_lua.add_source_files(env.modules_sources, "lua_libraries.gen.cpp")
+env_lua.Append(CPPPATH=[Dir('.').abspath])
diff --git a/lua_libraries/codegen.py b/lua_libraries/codegen.py
new file mode 100644
index 00000000..b0d142c9
--- /dev/null
+++ b/lua_libraries/codegen.py
@@ -0,0 +1,95 @@
+import os
+
+def code_gen(luaJIT=False):
+ lua_libraries = [
+ "base",
+ "coroutine",
+ "debug",
+ "io",
+ "math",
+ "os",
+ "package",
+ "string",
+ "table",
+ "utf8"
+ ]
+
+ luajit_libraries = [
+ "base",
+ "bit",
+ "debug",
+ "ffi",
+ "io",
+ "jit",
+ "math",
+ "os",
+ "package",
+ "string",
+ "string_buffer",
+ "table"
+ ]
+
+ libraries = lua_libraries
+ lib_source_files = []
+
+ if luaJIT:
+ libraries = luajit_libraries
+
+ for library in os.listdir("./"):
+ if not os.path.isdir(library) or library == "__pycache__" or library == "bin":
+ continue
+
+ libraries.append(library)
+
+ for source_file in os.listdir("./%s" % library):
+ if source_file.endswith(".cpp") or source_file.endswith(".c"):
+ lib_source_files.append(os.path.join(library, source_file))
+
+ luaLibraries_gen_cpp = "#include \"lua_libraries.h\"\n#include