• Stars
    star
    308
  • Rank 135,712 (Top 3 %)
  • Language
    Lua
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Godot PluginScript for the Lua language, currently based on LuaJIT's FFI

Godot Lua PluginScript

Lua PluginScript icon

Godot Asset Library Icon Pluginscript Lua

Warning

This does not work with Godot 4.X, since it relies on GDNative, a Godot 3.X only technology.

GDNative + PluginScript library that adds support for Lua as a scripting language in Godot 3.X

Being a GDNative library, recompiling the engine is not required, so anyone with a built release copied to their project can use it. Being a PluginScript language, Lua can seamlessly communicate with scripts written in GDScript / C# / Visual Script and vice-versa. Since the Godot object model is dynamic at runtime, any Godot objects' properties/methods can be accessed from Lua, including singletons like OS, ClassDB and custom singleton nodes. This way, one can use the language that best suits the implementation for each script and all of them can understand each other.

This plugin is available in the Asset Library as Lua PluginScript.

For some usage examples, check out plugin/lua_repl.lua and plugin/export_plugin.lua.

Currently, only LuaJIT is supported, since the implementation is based on its FFI library.

Installing

Either:

  • In Godot Editor, open the Asset Library tab, search for the Lua PluginScript asset, download and install it.
  • Put a built release of the library into the project folder and restart Godot. Make sure the lua_pluginscript.gdnlib file is located at the res://addons/godot-lua-pluginscript folder.
  • Clone this repository as the project's res://addons/godot-lua-pluginscript folder and build for the desired platforms.

Documentation

Goals

  • Provide support for Lua as a scripting language in Godot in a way that does not require compiling the engine from scratch
  • Be able to seamlessly communicate with any other language supported by Godot, like GDScript, Visual Script and C#, in an idiomatic way. This includes being able to dynamically access any Godot object's properties and methods using Lua's index/method notation
  • Have automatic global access to Godot's singleton objects and custom singleton nodes
  • Simple script description interface that doesn't need requireing anything
  • Support for LuaJIT and Lua 5.2+
  • Support paths relative to res://* and exported game/app executable path for requireing Lua modules
  • Have a simple build process, where anyone with the cloned source code and installed build system + toolchain can build the project in a single step

Non-goals

  • Provide calls to core Godot classes' methods via native method bindings
  • Support multithreading on the Lua side

Articles

  1. Designing Godot Lua PluginScript
  2. Implementing the library's skeleton
  3. Integrating LuaJIT and FFI
  4. Initializing and finalizing scripts (TODO)

Script example

This is an example of how a Lua script looks like.

-- Class definitions are regular Lua tables, to be returned from the script
local MyClass = {}

-- Optional: set class as tool, defaults to false
MyClass.is_tool = true

-- Optional: set base class by name, defaults to 'Reference'
MyClass.extends = Node

-- Optional: give your class a name
MyClass.class_name = 'MyClass'

-- Declare signals
MyClass.something_happened = signal()
MyClass.something_happened_with_args = signal("arg1", "arg2")

-- Values defined in table are registered as properties of the class
-- By default, properties are not exported to the editor
MyClass.some_prop = 42

-- The `property` function adds metadata to defined properties,
-- like setter and getter functions
MyClass.some_prop_with_details = property {
  -- ["default_value"] or ["default"] or [1] = property default value
  5,
  -- ["type"] or [2] = variant type, optional, inferred from default value
  -- All Godot variant type names are defined globally as written in
  -- GDScript, like bool, int, float, String, Array, Vector2, etc...
  -- Notice that Lua <= 5.2 does not differentiate integers from float
  -- numbers, so we should always specify `int` where appropriate
  -- or use `int(5)` in the default value instead
  type = int,
  -- ["get"] or ["getter"] = getter function or method name, optional
  get = function(self)
    return self.some_prop_with_details
  end,
  -- ["set"] or ["setter"] = setter function or method name, optional
  set = 'set_some_prop_with_details',
  -- ["usage"] = property usage, from `enum godot_property_usage_flags`
  -- optional, default to `PropertyUsage.NOEDITOR`
  usage = PropertyUsage.NOEDITOR,
  -- ["hint"] = property hint, from `enum godot_property_hint`
  -- optional, default to `PropertyHint.NONE`
  hint = PropertyHint.RANGE,
  -- ["hint_string"] = property hint text, only required for some hints
  hint_string = '1,10',
  -- ["rset_mode"] = property remote set mode, from `enum godot_method_rpc_mode`
  -- optional, default to `RPCMode.DISABLED`
  rset_mode = RPCMode.MASTER,
}
-- The `export` function is an alias for `property` that always exports
-- properties to the editor
MyClass.exported_prop = export { "This property appears in the editor" }
MyClass.another_exported_prop = export {
  [[This one also appears in the editor,
now with a multiline TextArea for edition]],
  hint = PropertyHint.MULTILINE_TEXT,
}

-- Functions defined in table are public methods
function MyClass:_ready()  -- `function t:f(...)` is an alias for `function t.f(self, ...)`
  -- Singletons are available globally
  local os_name = OS:get_name()
  print("MyClass instance is ready! Running on a " .. os_name .. " system")

  -- There is no `onready` keyword like in GDScript
  -- Just get the needed values on `_ready` method
  -- Also, Lua doesn't have the `$child_node` syntax, use `get_node` instead
  self.some_grandchild_node = self:get_node("some/grandchild_node")
end

function MyClass:set_some_prop_with_details(value)
    self.some_prop_with_details = value
    -- Indexing `self` with keys undefined in script will search base
    -- class for methods and properties
    self:emit_signal("something_happened_with_args", "some_prop_with_details", value)
end

function MyClass:get_some_prop_doubled()
  return self.some_prop * 2
end

-- In the end, table with class declaration must be returned from script
return MyClass

Status

  • LuaJIT support
  • Lua 5.2+ support
  • Useful definitions for all GDNative objects, with methods and metamethods
  • A yield function similar to GDScript's, to resume after a signal is emitted (GD.yield)
  • Working PluginScript language definition
  • PluginScript script validation and template source code
  • PluginScript code editor callbacks
  • PluginScript debug callbacks
  • PluginScript profiling callbacks
  • Package searcher for Lua and C modules that work with paths relative to the res:// folder and/or exported games' executable path
  • Lua REPL
  • API documentation
  • Unit tests
  • Example projects
  • Export plugin to minify Lua scripts
  • Drop-in binary release in GitHub
  • Submit to Asset Library

Third-party software

This project uses the following software:

  • godot-headers: headers for GDNative, distributed under the MIT license
  • LuaJIT: Just-In-Time Compiler (JIT) for the Lua programming language, distributed under the MIT license
  • High Level GDNative (HGDN): higher level GDNative API header, released to the Public Domain
  • LuaSrcDiet: compresses Lua source code by removing unnecessary characters, distributed under the MIT license
  • LuaUnit: unit-testing framework for Lua, distributed under the BSD license
  • debugger.lua: dependency free, single file embeddable debugger for Lua, distributed under the MIT license

Other projects for using Lua in Godot

More Repositories

1

godot-dockable-container

Dockable/tiling UI panels Container addon for Godot
GDScript
189
star
2

unity-texture-apply-async

Alternative to Texture2D.Apply() that doesn't require synchronizing with the render thread, avoiding stalls in the main thread
C
110
star
3

unity-flex-ui

Flexbox layout support for Unity UI using the Yoga layout engine
C#
100
star
4

unity-update-manager

Simple to use Update Manager pattern for Unity + Jobified Update for MonoBehaviours and pure C# classes alike
C#
85
star
5

unity-sqlite-net

SQLite-net for Unity, supports Windows, Linux, macOS, iOS, tvOS, visionOS, Android and WebGL
C
65
star
6

lua-gdextension

Extension for using the Lua programming language in Godot 4.1.2+
C++
62
star
7

hello-gdextension

Samples and experiments using Godot 4 + GDExtension
C
48
star
8

unity-gradle-wrapper

Automatically generate Gradle Wrapper (gradlew) when exporting Android projects in Unity
C#
42
star
9

unity-safe-area-layout

uGUI layout group that makes children respect the Safe Area. It drives children's anchors and supports LayoutElement.ignoreLayout
C#
42
star
10

godot-dispatch-queue

Threaded and synchronous Dispatch Queues for Godot
GDScript
40
star
11

unity-camera-viewport-rect

Automatically setup Camera viewports from RectTransforms in Unity
C#
35
star
12

unity-camera-fov-fit

Automatically adjust cameras' FOV to 3D objects bounds in Unity
C#
24
star
13

unity-lottie-player

Player for Lottie animations, powered by rlottie, multithread/Job System-friendly
C#
23
star
14

unity-key-value-store

Key-Value Store save system interface and implementations for Unity
C#
22
star
15

godot-cubic-bezier-controls

Godot addon defining Cubic Bezier Curve Resource and Controls for visualizing and editing them
GDScript
20
star
16

high-level-gdnative

Single header GDNative high level API for C/C++
C++
19
star
17

pega-texto

Single-file Parsing Expression Grammars (PEG) runtime engine for C
C
18
star
18

unity-gradient-rect

Component that draws a Gradient using Unity UI
C#
17
star
19

raylib-meson-template

Minimal template project for C/C++ applications using raylib built using Meson
Meson
17
star
20

draw-over

Drawing application with support for transparent background, working both as a drawing board or on-screen annotation tool
GDScript
17
star
21

unity-managed-jobs

Use classes and other managed types with Unity's Job System
C#
16
star
22

godot-lua-pluginscript-distribution

Distribution repository for Godot Lua PluginScript, submitted to the Asset Library
Lua
12
star
23

unity-easy-project-settings

Easily create custom Project Settings by adding [ProjectSettings(...)] attribute to your ScriptableObject subclass
C#
12
star
24

bettercmath

A -betterC compatible 3D math library for D
D
10
star
25

unity-gesture-recognizers

Gesture recognizer scripts for Unity based on Input and EventSystem handlers
C#
10
star
26

inclua

C to scripting languages wrapper generator, INitialy for binding C to LUA
Mako
10
star
27

godot-input-key-event-grabber

Godot plugin with a button that grabs key events and populate an InputEventKey instance, great for creating ShortCut resources
GDScript
8
star
28

TaskFactoryObject

TaskFactory Unity objects plus a collection of TaskSchedulers with optional limited concurrency
C#
8
star
29

unity-conditional-objects

Unity scripts that modify GameObjects and Components at Prefab/Scene import time based on build configurations
C#
8
star
30

unity-serializable-collections

Serializable versions of Dictionary, HashSet and KeyValuePair for Unity 2020.1+
C#
7
star
31

gdextension-lite

Automatically generated header-only GDExtension bindings for C/C++
C
7
star
32

unity-runtime-preset

Functionality analogous to Unity's Preset that can be used at runtime and prefab/scene import time
C#
7
star
33

unity-back-button-stack

Easily manage a stack of objects that respond to the ESC button / Android Back button in Unity, so that only the top object handles the event.
C#
6
star
34

AssetList

ScriptableObject that automatically aggregates assets using AssetDatabase.FindAssets
C#
6
star
35

c_api_extract-py

Automatic extraction of C APIs from header files using Python and libclang
Python
6
star
36

lallegro

Lua bindings for the Allegro 5.2 game programming library
Lua
6
star
37

unity-enum-bitset

Fast and memory efficient implementation of C#'s ISet for enums, storing data as bit masks
C#
6
star
38

unity-prefab-pool

Prefab instance pool that is configurable in the Inspector, supports any engine Object type and is available as a serializable C# class, MonoBehaviour and ScriptableObject
C#
6
star
39

molde

Zero dependency, single file template engine for Lua 5.1+ with builtin sandbox support
Lua
6
star
40

hell

Hell build system: "to hell with building software!"
Lua
5
star
41

raise-and-shine

Height map editor with automatic normal map generation for 2D textures
GDScript
5
star
42

unity-rounded-corners

UI components with rounded corners embedded in their meshes for Unity
C#
5
star
43

unity-tween-jobs

Tween engine for Unity based on the C# Job System
C#
5
star
44

unity-lyon-tessellation

Tessellation of vector paths in Unity, powered by lyon
C#
5
star
45

betterclist

A -betterC compatible dynamic list backed by array for D
D
4
star
46

unity-non-alloc-enumeration

Non-alloc enumerables for Unity structures and C# IList/IReadOnlyList
C#
4
star
47

soa-d

A -betterC compatible Struct Of Arrays template for D
D
4
star
48

objectivec-gdextension

Experimental GDExtension for calling Object-C methods at runtime in Godot 4.1+
Objective-C++
4
star
49

gargula

Game engine based on nested structs and compile-time tree traversals powered by raylib and D compatible with betterC
D
4
star
50

c-allocators

A collection of public domain single-file custom allocators for C/C++
C
4
star
51

cffi-gdextension

libffi bindings for Godot 4.1+
C++
4
star
52

wildcard_pattern-lua

Lua library for using shell-like wildcards as string patterns with support for importing gitignore-like file content
Lua
3
star
53

xadrezaoDoBatistao

Java
3
star
54

unity-ui-corner-offset

Corner Offset mesh modifier for Unity UI, useful for shearing/skewing Graphics
C#
3
star
55

WebGlJsInjector

Import JavaScript code as <script> tags in Unity WebGL builds' index.html file
C#
3
star
56

unity-objectivec

High level C# to Objective-C interface, similar to Unity's AndroidJavaClass and AndroidJavaObject
C#
3
star
57

high-level-gdnative-example

Example project for High level GDNative C/C++ API (HGDN)
C
3
star
58

csfml-luajit

LuaJIT FFI bindings for CSFML
Lua
3
star
59

unity-audio-latency

Utilities for finding audio latency
C#
3
star
60

unity-key-value-store-icloud-kvs

Key-Value Store implementation for Unity backed by iCloud KVS
C#
3
star
61

unity-sqlite-asset

Read-only SQLite database assets for Unity with ScriptedImporters for ".sqlite", ".sqlite2" and ".sqlite3" files
C#
3
star
62

godot-auto-scroll-label

Label that animates the text scrolling when it does not fit in its rect for Godot
GDScript
2
star
63

NamedEnum

Safer alternative to raw enums when used as serialized fields in Unity, maintains the right values after reordering, resistant to code merges
C#
2
star
64

godot-fixed-cell-grid-container

Simple grid Container with fixed size cells for Godot
GDScript
2
star
65

godot-ecolocalizacao-2D

Teste de efeito de eco localização em 2D usando Godot
GDScript
2
star
66

unity-get-component-context-menu

Context menu items for setting up Component references based on GetComponent* methods
C#
2
star
67

unity-scene-reference

Autogenerated ScriptableObjects that are stable references to the scenes configured in Build Settings, even if they are moved/renamed
C#
2
star
68

unity-main-thread-task

Task/UniTask-based Main Thread dispatcher classes, no GameObjects involved
C#
2
star
69

lua-gdextension-distribution

Distribution repository for Lua GDExtension, submitted to the Asset Library
Makefile
2
star
70

SSC0770-2020-S2-Audio

Projeto Unity pra aula sobre Audio da disciplina SSC0770
ShaderLab
2
star
71

unity-state-enum-sample

A sample Unity project using a state enum ScriptableObject + MonoBehaviours with UnityEvents
ShaderLab
2
star
72

nested

A generic nested data structure file format, where data is formed by nested lists with both sequential data and key-value paired data.
Lua
1
star
73

argmatcher

Simple command line argument matcher for Lua
Lua
1
star
74

petecataque

A game made with Lua + LÖVE + Nested
Lua
1
star
75

ecsql

Experimental ECS framework powered by SQLite
C
1
star
76

bode-espirratorio

GDScript
1
star
77

godot-moonscript-import-plugin-poc

Proof of concept import plugin for using MoonScript in Godot, based on Lua PluginScript
Lua
1
star
78

unity-webgl-emscripten-settings

Unity Project Settings tab that allows editing PlayerSettings.WebGL.emscriptenArgs
C#
1
star
79

gogodotjam1

Game made for Go Godot Jam 1
GDScript
1
star
80

StreamingJson

A streaming JSON parser for desserializing structured data for Unity
C#
1
star
81

tuirm

A ncurses based Terminal UI toolkit in Lua
Lua
1
star
82

lualvm

Lua wrapper for the LLVM-C API
Lua
1
star
83

d-sokol-game

An experimental game made using D + sokol_gfx
C
1
star
84

ggj2021

Game made for Global Game Jam Online 2021
GDScript
1
star
85

unity-playerloophelper

Single file helper class for registering/unregistering systems in Unity's PlayerLoop.
C#
1
star
86

fswatch-luajit

LuaJIT FFI and wrapper for libfswatch (https://github.com/emcrisostomo/fswatch)
Lua
1
star
87

lap

Lambda Argument Parser, a C++11 library for parsing command line arguments
C++
1
star
88

SOTreta

Jogo feito na Semcomp Game Jam 2017
PHP
1
star
89

Godot-KeyShortcutCreator

A creator for InputEventKey Shortcut resources with direct keyboard input instead of looking up scancodes manually
GDScript
1
star
90

unity-key-value-store-sqlite

Key-Value Store implementation backed by the SQLite database engine
C#
1
star
91

unity-reset-after-play-mode

Editor-only ScriptableObject that resets other assets' properties after exiting Play Mode to avoid unwanted diffs in version control
C#
1
star
92

unity-key-value-store-apple-keychain

Key-Value Store implementation for Unity backed by macOS/iOS/tvOS/visionOS Keychain services
C#
1
star
93

d-raylib-pongstruct

D + Raylib powered Pong game with no class (structs only)
D
1
star
94

unity-native-collections-stream

Stream, TextReader and TextWriter implementations backed by Unity Native Collections
C#
1
star
95

unity-sqlite-asset-csv

Easily import ".csv" files as read-only SQLite database assets in Unity
C#
1
star
96

idbvfs

WebAssembly SQLite VFS for web browsers, powered by IndexedDB
C
1
star
97

flyweight.hpp

Single header implementation of the Flyweight design pattern for C++11
C++
1
star