Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3d9c1f3
WIP Add code generator for Lua API to use with LLS
gilzoide Jan 4, 2026
0d57a9a
WIP Generate Lua API definition file for classes
gilzoide Jan 4, 2026
a5c203e
Add `new` method to instantiable classes that are not singletons
gilzoide Jan 4, 2026
86646a4
Fix register class enum values directly instead of inside table
gilzoide Jan 4, 2026
e0473d5
Add functions for bool, int and float
gilzoide Jan 4, 2026
f7ed88e
Fix static methods using `:` and add support for nullable parameters
gilzoide Jan 4, 2026
29c8a28
Use explicit self in Variant methods
gilzoide Jan 4, 2026
e9d4511
Add constructors for Variant
gilzoide Jan 4, 2026
c7282a8
Mark String/StringName as aliases to string
gilzoide Jan 4, 2026
8c15626
Generate Lua API file with utility functions
gilzoide Jan 4, 2026
b598842
Use `any` instead `Variant` for type annotations
gilzoide Jan 4, 2026
b9a7058
Fix name of C++ code generator script in generated code
gilzoide Jan 4, 2026
fef2b26
Add .luarc.json to exported build from CI
gilzoide Jan 4, 2026
271e530
Add target alias "lua_api", build lua_api on CI
gilzoide Jan 4, 2026
facf418
Merge branch 'main' into feature/lua-language-server-support
gilzoide Jan 4, 2026
2eeb004
Add await to utility functions
gilzoide Jan 5, 2026
bcf801e
Add signals to class API
gilzoide Jan 5, 2026
8e2e9ab
Fix add utility_functions.lua to .luarc.json
gilzoide Jan 5, 2026
ab31639
Use folder instead of listing every Lua file
gilzoide Jan 5, 2026
c9edc08
Make Object inherit Variant
gilzoide Jan 5, 2026
5acd312
Add `{ [...]: ...}` inheritance to indexable classes
gilzoide Jan 5, 2026
6cdf2da
Change key type for indexing classes to `string` instead of `any`
gilzoide Jan 5, 2026
df0927a
Merge branch 'main' into feature/lua-language-server-support
gilzoide Jan 10, 2026
63602e9
Add manually defined globals as a separate file
gilzoide Jan 10, 2026
343c24a
Add LuaScriptLanguage specific definitions in a new definitions file
gilzoide Jan 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ indent_size = 4

[*.bat]
end_of_line = crlf

[.luarc.json]
indent_style = space
indent_size = 4
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,15 @@ jobs:
scons-version: $SCONS_VERSION
- name: Copy artifacts to build folder
run: |
scons lua_runtime=${{ matrix.lua-runtime }} addons_files
scons lua_runtime=${{ matrix.lua-runtime }} addons_files lua_api
cp -r ${{ steps.download.outputs.download-path }}/**/lib* addons/lua-gdextension/build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.lua-runtime == 'lua' && 'lua-gdextension' || format('lua-gdextension+{0}', matrix.lua-runtime) }}
path: |
LICENSE
.luarc.json
addons/lua-gdextension/**
addons/lua-gdextension/build/.gdignore
include-hidden-files: true
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ test/godot
.vs/
.vscode/

# Addons files
# Addons files generated by build
addons/lua-gdextension/CHANGELOG.md
addons/lua-gdextension/README.md
addons/lua-gdextension/LICENSE
addons/lua-gdextension/lua_api_definitions/builtin_classes.lua
addons/lua-gdextension/lua_api_definitions/classes.lua
addons/lua-gdextension/lua_api_definitions/global_enums.lua
addons/lua-gdextension/lua_api_definitions/utility_functions.lua
7 changes: 7 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"workspace": {
"library": [
"addons/lua-gdextension/lua_api_definitions"
]
}
}
Empty file.
83 changes: 83 additions & 0 deletions addons/lua-gdextension/lua_api_definitions/lua_script_language.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
--- @meta

-----------------------------------------------------------
-- Properties
-----------------------------------------------------------

--- @class LuaScriptProperty
--- Property definition for Lua scripts.
LuaScriptProperty = {}

--- Used to define custom properties in Lua scripts.
--- If you pass a table, the following keys are used (all are optional):
--- + `1`: if it's a Variant type or Class (like `Dictionary` or `Node2D`) it represents the property type.
--- Otherwise, it represents the property's default value.
--- + `type`: should be a Variant type or a Class, such as `Vector2` or `RefCounted`.
--- + `hint`: property hint (check out the `PropertyHint` enum for available values)
--- + `hint_string`: property hint string, depends on the value of `hint`
--- + `usage`: property usage flags (check out the `PropertyUsage` enum for available values)
--- + `class_name`: the name of the Class, filled automatically from `type` if it's a Class type
--- + `default`: the default value of the property
--- + `get`: getter function, should be either a Lua function or a string containing the getter method name
--- + `set`: setter function, should be either a Lua function or a string containing the setter method name
---
--- In case `t` is not a table, the table `{t}` will be used instead.
--- @param t table | any
--- @return LuaScriptProperty
function property(t) end

--- Used to define exported properties in Lua scripts.
--- This is the same as `property`, but always adds `PROPERTY_USAGE_EDITOR` to the property's usage flags.
---
--- @see property
--- @param t table | any
--- @return LuaScriptProperty
function export(t) end


-----------------------------------------------------------
-- Signals
-----------------------------------------------------------

--- @class LuaScriptSignal
--- Signal definition for Lua scripts.
LuaScriptSignal = {}

--- Used to define custom signals in Lua scripts.
--- For now there is no way to pass type information for arguments, only their names.
--- ```
--- local MyClass = {}
--- MyClass.some_signal = signal("argument1", "argument2")
--- return MyClass
--- ```
--- @param ... string
--- @return LuaScriptSignal
function signal(...) end


-----------------------------------------------------------
-- RPC configuration
-----------------------------------------------------------

--- Similar to GDScript's `@rpc` annotation, should be used to initialize the special `rpc_config`.
--- Example:
--- ```
--- local MyClass = {}
---
--- function MyClass:some_method() end
--- function MyClass:some_other_method() end
---
--- MyClass.rpc_config = {
--- "some_method" = rpc("any_peer", "call_local", "reliable", 0),
--- "some_other_method" = rpc("reliable", 1),
--- }
---
--- return MyClass
--- ```
--- See [@rpc](https://docs.godotengine.org/en/stable/classes/class_@gdscript.html#class-gdscript-annotation-rpc) for more information.
---
--- @param mode "any_peer" | "authority" | nil
--- @param sync "call_remote" | "call_local" | nil
--- @param transfer_mode "unreliable" | "unreliable_ordered" | "reliable" | nil
--- @param transfer_channel integer?
function rpc(mode, sync, transfer_mode, transfer_channel) end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- @meta

--- Yields the current coroutine until the passed signal is emitted.
--- If an Object is passed, awaits for its 'completed' signal.
--- This function should only be called inside a coroutine.
---
--- Note: only available if `GODOT_UTILITY_FUNCTIONS` library is open in the LuaState.
--- @param awaitable Object | Signal
--- @return any
function await(awaitable) end


--- Returns the Variant type of the passed value.
--- Contrary to GDScript's `typeof`, in Lua this does not return the enum like `TYPE_BOOL` or `TYPE_DICTIONARY`, but rather the actual class type like `bool` or `Dictionary`.
--- ```
--- if typeof(some_value) == Dictionary then
--- -- ...
--- end
--- ```
--- Note: only available if `GODOT_VARIANT` library is open in the LuaState.
--- @param value any
--- @return userdata?
function typeof(value) end
10 changes: 5 additions & 5 deletions tools/code_generation/generate_cpp_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _to_variant_type(s: str) -> str:

def generate_utility_functions(utility_functions):
lines = [
"// This file was automatically generated by generate_code.py\n#undef register_utility_functions\n#define register_utility_functions(state)",
"// This file was automatically generated by generate_cpp_code.py\n#undef register_utility_functions\n#define register_utility_functions(state)",
]
for f in utility_functions:
name = f["name"]
Expand All @@ -47,7 +47,7 @@ def generate_utility_functions(utility_functions):

def generate_enums(global_enums):
lines = [
"// This file was automatically generated by generate_code.py\n#undef register_global_enums\n#define register_global_enums(state)",
"// This file was automatically generated by generate_cpp_code.py\n#undef register_global_enums\n#define register_global_enums(state)",
]
for enum in global_enums:
lines.append(f"\t/* {enum['name']} */")
Expand All @@ -58,7 +58,7 @@ def generate_enums(global_enums):

def generate_package_searcher():
lines = [
"// This file was automatically generated by generate_code.py",
"// This file was automatically generated by generate_cpp_code.py",
"const char package_searcher_lua[] = ",
]
with open(PACKAGE_SEARCHER_SRC, "r", encoding="utf-8") as f:
Expand All @@ -71,7 +71,7 @@ def generate_package_searcher():

def generate_lua_script_globals():
lines = [
"// This file was automatically generated by generate_code.py",
"// This file was automatically generated by generate_cpp_code.py",
"const char lua_script_globals[] = ",
]
with open(LUA_SCRIPT_GLOBALS_SRC, "r", encoding="utf-8") as f:
Expand All @@ -84,7 +84,7 @@ def generate_lua_script_globals():

def generate_variant_type_constants(builtin_classes):
lines = [
"// This file was automatically generated by generate_code.py",
"// This file was automatically generated by generate_cpp_code.py",
"#include <godot_cpp/variant/variant.hpp>",
"using namespace godot;",
"",
Expand Down
Loading