raylib-lua but using luajit 2.0
Go to file
2020-09-18 21:39:10 +02:00
assets Update raylib binding, raylua version v3.0d. 2020-05-26 21:40:13 +02:00
examples Indentation fixes 2020-09-05 20:44:37 +02:00
luajit@76958aa0c4 MoonJIT 2020-04-11 15:38:34 +02:00
raygui@07b30c30af Update raylib, reimplement deprecated LoadImageEx 2020-08-08 17:32:04 +02:00
raylib@79d63e6ca1 Update binding. 2020-09-18 18:10:29 +02:00
src Update binding. 2020-09-18 18:10:29 +02:00
tools Update binding. 2020-09-18 18:10:29 +02:00
.clang_complete Initial commit 2020-02-27 00:14:24 +01:00
.gitignore Add icon for Windows. 2020-05-10 13:43:22 +02:00
.gitmodules Fix lynx submodule on github. 2020-06-26 13:28:45 +02:00
.travis.yml Add travis 2020-09-18 21:39:10 +02:00
LICENCE Initial commit 2020-02-27 00:14:24 +01:00
makefile Update binding, more compatibility informations. 2020-09-05 16:15:31 +02:00
README.md Debugger support part 2020-09-05 20:44:49 +02:00

raylib-lua logo

release downloads

raylib-lua

LuaJIT-based binding for raylib, a simple and easy-to-use library to learn videogames programming.

This binding is partially based on raylib-wren/wray.

Usage (raylua_s)

raylua_s is the script-mode binary of raylib-lua. Without any argument, you get into the REPL which gives you a minimal Lua] shell that allows you to run Lua code from terminal.]

You can specify a Lua file as argument to run the specified Lua file.

Usage (raylua_e)

raylua_e is the embedding-mode binary of raylib-lua.

This binary allows you to build standalone raylib applications from Lua code.

There are 3 ways to use it :

  • zip mode : If you specify a zip file as argument, this zip will be used as payload application, this file expects to have a main.lua which is the entry point of the application.
  • directory mode : Similar to zip mode except that it automatically build the zip payload from the specified directory.
  • lua mode : Build the executable from a single Lua file.

Using require in embedded mode works as expected but dofile and loadfile may not work as expected as these functions load from a external file rather than from package loaders.

Building / Updating raylib / Contribution

To build raylib-lua from source, you need to take care that submodules are imported, if not or you are unsure :

git submodule init
git submodule update

This make take some time depending on network bandwidth. Then, raylib-lua should build as expected using make tool with a working C compiler.

A working Lua interpreter is needed, by default the luajit interpreter built along with libluajit.a is used. In case of cross-compiling, you may want to change which Lua interpreter is used to a one your system supports. You can specify the interpreter with the LUA variable.

If you need to update raylib binding, there are few tasks to do :

  • update tools/api.h functions signatures, keep file clean with exactly one function per line.
  • update struct definitions in src/raylib.lua

Loading embedded ressources

Currently, raylib-lua doesn't support loading ressources from payload using raylib API. However, you can still arbitrarily load files from payload using raylua.loadfile which returns a boolean indicating success and file content.

Making structs

To make raylib structs, you need to use the LuaJIT FFI.

local ffi = require "ffi"

Then use ffi.new to make a struct, e.g ffi.new("Color", r, g, b, a)

Note concerning pointers

You can use rl.ref to build a pointer from a struct cdata. This functions only work struct cdata, in case of primitive cdata, you need to make a array and pass it directly.

e.g :

local int_ptr = ffi.new "int [1]"
local data = tostring(rl.LoadFileData("test.txt", int_ptr))
local count = tonumber(int_ptr[0])

Example

rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)

rl.InitWindow(800, 450, "raylib [core] example - basic window")

while not rl.WindowShouldClose() do
	rl.BeginDrawing()

	rl.ClearBackground(rl.RAYWHITE)
	rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY)

	rl.EndDrawing()
end

rl.CloseWindow()

Compatibility

raylib-lua (raylua) currently uses raylib 3.1-dev API with some 3.0 API compatibility (see compat.lua). physac and rlgl modules are built-in by default. raygui is supported, but is minimally tested, please report any issues you have with raygui with raylib-lua (raylua) on GitHub or raylib Discord (#raylib-lua channel)

Global API

You can make raylib-lua (raylua) partially compatible with original raylib-lua or raylib-lua-sol with global API by adding setmetatable(_G, { __index = rl }) on the first line.

This will allow direct use of the raylib binding through globals instead of rl table.

You have an example of this in lua_global_api.lua.

Editor support

Currently, there is no editor autocompletion/integration support for most editors, but there is a third-party autocompletion support for ZeroBrane Studio by Rabios.

Debugging

You can use Local Lua Debugger for Visual Studio Code to provide debugging support with Visual Studio Code. You need to add this at the beginning of your code to use it :

do local f = getmetatable(rl).__index;rawset(rl, "__index", function (_, k) return select(2, pcall(f, _, k)) end) end
package.path = package.path .. os.getenv "LUA_PATH"
local lldebugger = require "lldebugger"; lldebugger.start()

You also need to setup a launch configuration in Visual Studio Code to run raylua_s with debugger attached, e.g

{
    "type": "lua-local",
    "request": "launch",
    "name": "(Lua) Launch",
    "cwd": "${workspaceFolder}",
    "program": { "command": "PATH TO raylua_s" },
    "args": [ "main.lua OR ${file} OR WHATEVER" ]
}

This debugger doesn't support pausing, you need to place a breakpoint before executing to get a actual debug, otherwise, a error needs to be thrown in the application to get the debugging. This debugger has a significant overhead, expect a performance loss in intensive projects.

Other bindings

raylib-lua (raylua) is not the only Lua binding for raylib.

There are some other bindings, which may or may not be up to date.

RobLoach/raylib-lua-sol

raysan5/raylib-lua

HDPLocust/raylib-luamore

alexander-matz ffi binding

darltrash/raylib-luajit

Rabios/raylua

Licence

Copyright (C) 2020 Astie Teddy

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.