Skip to content

An attempt at Raylib LuaJit bindings that are generated from the raylib-parser API docs

License

Notifications You must be signed in to change notification settings

james2doyle/raylib-luajit-generated

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raylib LuaJit 5.5

Raylib LuaJit bindings that are generated from the raylib-parser API docs

!! INCOMPLETE AND WORK IN PROGRESS !!

  • raylib.h code-gen to lua using raylib_api.lua
  • rlgl.h code-gen to lua using rlgl_api.lua
  • raygui.h code-gen to lua using raygui_api.lua
  • config.h code-gen to lua using config_api.lua
  • raymath.h code-gen to lua using raymath_api.lua
PROS:
  • Simple lua files (except for the compiled Raylib binaries/libraries/header)
  • Works as an actual lib instead of a runner
  • No build required in order to use this
  • Really easy to update
CONS:
  • You need the LuaJIT and Raylib compiled binaries/libraries
  • Building a binary to distribute is a chore

Running

  • Install Raylib globally. I used brew install raylib on OSX, or
  • Download your Raylib release and toss everything from lib/ into the ./raylib folder
  • Create a file in the root with the following code:
-- save as main.lua
-- run with `luajit main.lua`
local rl = require('raylib')

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()
  • Run luajit main.lua

Examples

Examples are pulled from TSnake41/raylib-lua

Run luajit examples/core_basic_window.lua

Generating API files

You can use the Raylib parser to generate .lua files that document the API:

./raylib_parser -i ../src/config.h -f LUA -o config_api.lua
./raylib_parser -i ../src/raylib.h -f LUA -o raylib_api.lua
./raylib_parser -i ../src/raymath.h -f LUA -o raymath_api.lua
./raylib_parser -i ../src/rlgl.h -f LUA -o rlgl_api.lua
# requires the raygui in the raylib source folder
./raylib_parser -i ../raygui/src/raygui.h -f LUA -o raygui_api.lua

Building raylib/init.lua from API files

This is a work in progress as well. It uses regular Lua 5.4 to generate the file. Make sure lpeg is installed. You can install it with luarocks install lpeg.

It is super rough right now but it does work and generates a init.lua file with comments and docblocks!

You don't need Lune or Luau installed to use this library

cd raylib/
luarocks install lpeg
lua generate.lua

Thank you to the following projects

Thank you to these projects that acted as a reference for this implementation

About

An attempt at Raylib LuaJit bindings that are generated from the raylib-parser API docs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published