tsnake41 / raylib-lua Goto Github PK
View Code? Open in Web Editor NEWA modern LuaJIT binding for Raylib (also available at https://gitlab.com/TSnake41/raylib-lua)
License: ISC License
A modern LuaJIT binding for Raylib (also available at https://gitlab.com/TSnake41/raylib-lua)
License: ISC License
missing declaration for symbol 'CreateLight'
The function CreateLight is not present in your package but raylib 4.5-dev contains it.
Hi, I think I've found an issue when trying to define a varargs function. Here's an example:
function util.pyprint(...)
res = ""
for k, v in ipairs(arg) do
print("k = " .. tostring(k) .. ", v = " .. tostring(v))
res = res .. tostring(v)
end
print(res)
end
This function is supposed to print variable argument and is intentionally similar to python's print
. I added another print
call for debugging purposes. When I run this function, with any kind and number of arguments, I get this output:
k = 1, v = test.lua
test.lua
(test.lua
being the input file for raylua_s
).
I would like to ask how this binder works and how to correctly use it. I never used binders and the only thing i understand now is how to run the project for linux but what if i want to build it for windows and etc.. Is there some info on how to do stuff like this?
I updated the binary (its the only change I made to the code) and now the program ignores collisions
function collision()
local collision = false
for k,v in pairs(o) do
if rl.CheckCollisionBoxes(
{{ pl.pos.x - pl.size.x/2, pl.pos.y - pl.size.y/2, pl.pos.z - pl.size.z/2 },
{ pl.pos.x + pl.size.x/2, pl.pos.y + pl.size.y/2, pl.pos.z + pl.size.z/2 }},
{{ o[k][1][1] - o[k][2][1]/2, o[k][1][2] - o[k][2][2]/2, o[k][1][3] - o[k][2][3]/2},
{ o[k][1][1] + o[k][2][1]/2, o[k][1][2] + o[k][2][2]/2, o[k][1][3] + o[k][2][3]/2 }}) == false then
collision = false
else
collision = true
break
end
return collision
end
end
the function was taken from a raylib example and as I said it was totally working and shiet but now it no longer works 😢
This may seem strange, but I would like to know if there is a possibility to have the executables without the built-in raylib.
The reason for this is that I have been looking for an efficient way to get all the files from a program made in lua for a while, and put them inside an executable / binary
The problem is that none is 100% perfect, but testing with raylua, I can get it to work with any other library and files I want, I did a test with sdl.
The only problem is that it already has raylib built in, giving it a hefty size of 2.5mb, and I would like to have a compiler option without raylib built in.
I see huge potential for this to become the best "compiler" for lua.
I also accept instructions on how to compile the program without raylib. Thanks in advance for the answer.
As the title says, I can't use it, I've tried everything. I even made sure that the font was in the path.
sorry i am no c programmer i have no ideia why it doesnt work but it doesnt work
the following example works fine when running in scritpt mode but not when i build the exe
local width, height = 800, 450
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
rl.InitWindow(800, 450, "raylib")
rl.InitAudioDevice()
local logo = rl.LoadTexture "assets/logo.png"
local music = rl.LoadMusicStream "assets/music/music.ogg"
rl.PlayMusicStream(music)
while not rl.WindowShouldClose() do
rl.UpdateMusicStream(music)
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
rl.DrawTexture(logo, width/2 - logo.width/2, height/2 - logo.height/2, rl.WHITE)
rl.DrawText("this is a texture!", 350, 370, 10, rl.GRAY)
rl.EndDrawing()
end
rl.UnloadMusicStream(music)
rl.CloseAudioDevice()
rl.CloseWindow()
the raylib output indicates that files were loaded succesfully, and if I remove the rl.UpdateMusicStream it seems to work fine (although the music wont play)
The README.md
currently has the following in it:
raylib-lua (raylua) currently uses raylib 3.5 API.
However, elsewhere on the repository and also on the big raylib bindings list this library's version is listed as being 4.5.
Is this bindings library still using 3.5 for some parts of its code or has that text simply not been updated yet?
Should that version number be changed to 4.5?
Anyway, thank your for your time and for your work on this bindings library. I look forward to trying it out. 😎
Hi, first of all, thanks for the amazing work with raylib-lua, this is definitely the best raylib port for lua that I could find, it meets all my requirements. However, I am having a small problem and would like instructions to fix it, as I have no experience with c.
When I run raylua_s, it runs the REPL normally, however, when I try to start a window, with the following code, it returns the following error:
Code:
local screenWidth = 800
local screenHeight = 450
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window")
rl.SetTargetFPS(60)
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.DrawFPS(10, 10)
rl.EndDrawing()
end
rl.CloseWindow()
Error:
$ ./raylua_s main.lua
RAYLUA: Raylua boot script
RAYLUA: Lua Version: Lua 5.1
RAYLUA: Lua JIT: LuaJIT 2.1.0-beta3
RAYLUA: Loading FFI binding entries.
RAYLUA: Loaded 823 FFI entries.
INFO: Initializing raylib 4.0
WARNING: GLFW: Error: 65543 Description: GLX: Failed to create context: GLXBadFBConfig
WARNING: GLFW: Failed to initialize Window
FATAL: Failed to initialize Graphic Device
$
I researched, and I didn't find any solution regarding raylib.
I would be very grateful if you could help me resolve this error.
Grateful for the answer.
examples gui_portable_window.lua:
#!/home/maik_ubn/raylib-lua/raylua_s
local width, height = 1280, 720
rl.SetConfigFlags(rl.FLAG_WINDOW_UNDECORATED)
rl.InitWindow(width, height, "raygui - portable window")
rl.SetTargetFPS(75)
local mouse_pos = rl.new("Vector2", 0, 0)
local window_pos = rl.GetWindowPosition()
local pan_offset = rl.new("Vector2", mouse_pos)
local drag_window = false
local exit_window = false
while not exit_window and not rl.WindowShouldClose() do
print(exit_window, rl.WindowShouldClose()) --> false false
mouse_pos = rl.GetMousePosition()
if rl.IsMouseButtonPressed(rl.MOUSE_BUTTON_LEFT) then
if rl.CheckCollisionPointRec(mouse_pos, rl.new("Rectangle", 0, 0, width, 20)) then
drag_window = true
pan_offset = rl.new("Vector2", mouse_pos)
end
end
if drag_window then
window_pos = window_pos + mouse_pos - pan_offset
if rl.IsMouseButtonReleased(rl.MOUSE_BUTTON_RIGHT) then
drag_window = false
end
rl.SetWindowPosition(window_pos.x, window_pos.y)
end
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
exit_window = rl.GuiWindowBox(rl.new("Rectangle", 0, 0, width, height), "PORTABLE WINDOW") -- return num
rl.DrawText(string.format("Mouse Position: [ %.0f, %.0f ]", mouse_pos.x, mouse_pos.y),
10, 40, 10, rl.DARKGRAY)
rl.EndDrawing()
print(exit_window, rl.WindowShouldClose()) --> 0, false --> not exit_window --> false
end
rl.CloseWindow()
The GuiWindowBox
function returns a number, but the examples don't take this into account.
I'm on a MacBook Air (M1, 2020) running macOS 12.4.
After cloning the repo and subrepos and running make
, trying to run any of the raylua_* binaries results in:
zsh: killed ./raylua_e
(…or raylua_s or raylua_r) and an exit code of 137.
Searching for "zsh: killed" seems to mostly result in pages relating to running Homebrew or tools installed with it on M1 Macs. I don't think this is Homebrew-related since I'm a boomer who uses MacPorts (if it ain't broke…). Nonetheless I wonder if the issue might still be related to the relatively new M1 hardware and I wonder if anyone else is seeing this issue happen on M1 Macs, or alternatley is running it successfully.
Unfortunately I no longer have easy access to Intel-based Mac hardware to see if the issue is happening there too.
I noticed there was no info on building for windows in the readme, it just says to download the prebuilt executables. Wanted to try the 5.0 branch, which isn't prebuilt yet, so I tried finding a reliable way to build it on Windows and I think that MSYS2 with the mingw64 environment active appears to be very reliable. I tested with the 4.5a source and the updated 5.0 source code on two different Windows machines and the builds worked as expected. Possibly worth a quick update to the readme?
Machines Testing (using both raylua_s.exe and raylua_e.exe):
Machine 1:
OS: Windows 11 Home 23H2
CPU: 11th Gen Intel Core i7-11800H @ 2.30GHz 2.30 GHz
GPU: RTX 3060
Machine 2:
OS: Windows 10 Home 22H2
CPU: AMD Ryzen 7-5700U @ 4.3GHz
GPU: Integrated AMD Radeon
-- you'll see I moved the images into the folder with the file and with luaJit.exe and the libaries
Here's the original C source
https://github.com/raysan5/raylib/blob/master/examples/textures/textures_background_scrolling.c
Where background, scrollingMid, scrollingFore are there's Texture2D statement ahead of them
but how do we do that in Lua?
All I get is crazy flashing window.
------- textures_background_scrolling.lua
local rl = require("raylib")
-- Initialization
local screenWidth = 800
local screenHeight = 450
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - background scrolling")
rl.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
-- NOTE: Be careful, background width must be equal or bigger than screen width
-- if not, texture should be draw more than two times for scrolling effect
background = rl.LoadTexture("cyberpunk_street_background.png")
midground = rl.LoadTexture("cyberpunk_street_midground.png")
foreground = rl.LoadTexture("cyberpunk_street_foreground.png")
scrollingBack = 0.0
scrollingMid = 0.0
scrollingFore = 0.0
while not rl.WindowShouldClose() do -- Detect window close button or ESC key
-- Update
------------------------------------------------------------------------------------
scrollingBack = scrollingBack- 0.1
scrollingMid = scrollingMid- 0.5
scrollingFore = scrollingFore- 1.0
-- NOTE: Texture is scaled twice its size, so it sould be considered on scrolling
if (scrollingBack <= -background.width*2) then scrollingBack = 0 end
if (scrollingMid <= -midground.width*2) then scrollingMid = 0 end
if (scrollingFore <= -foreground.width*2) then scrollingFore = 0 end
-- Draw
-----------------------------------------------------------------------------------
rl.BeginDrawing()
--ClearBackground(GetColor(0x052c46ff))
rl.ClearBackground(rl.RAYWHITE)
-- Draw background image twice
-- NOTE: Texture is scaled twice its size
rl.DrawTextureEx(background, (Vector2){ scrollingBack, 20 }, 0.0, 2.0, WHITE)
rl.DrawTextureEx(background, (Vector2){ background.width*2 + scrollingBack, 20 }, 0.0, 2.0, rl.WHITE)
--Draw midground image twice
rl.DrawTextureEx(midground, (Vector2){ scrollingMid, 20 }, 0.0, 2.0, WHITE)
rl.DrawTextureEx(midground, (Vector2){ midground.width*2 + scrollingMid, 20 }, 0.0, 2.0, rl.WHITE)
-- Draw foreground image twice
rl.DrawTextureEx(foreground, (Vector2){ scrollingFore, 70 }, 0.0, 2.0, WHITE)
rl.DrawTextureEx(foreground, (Vector2){ foreground.width*2 + scrollingFore, 70 }, 0.0, 2.0, rl.WHITE)
rl.DrawText("BACKGROUND SCROLLING & PARALLAX", 10, 10, 20, RED)
rl.DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, RAYWHITE)
EndDrawing()
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY)
rl.EndDrawing()
end
-- De-Initialization
----------------------------------------------------------------------------------------
rl.UnloadTexture(background) -- Unload background texture
rl.UnloadTexture(midground) -- Unload midground texture
rl.UnloadTexture(foreground) -- Unload foreground texture
rl.CloseWindow() -- Close window and OpenGL context
----------------------------------------------------------------------------------------
When I downloaded the compiled binaries for the raylib Lua bindings, I noticed that it had an extra EXE file in the zip file which was not mentioned anywhere on the README.md
page.
What is it intended for?
I think some comment about what it is should probably be added to the README.md
to avoid confusion.
when i execute the local raylib = require("raylib") it gives this error
lua: error loading module 'raylib' from file '.\raylib.lua':
C stack overflow
stack traceback:
[C]: in ?
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
... (skipping 370 levels)
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
raylib.lua:1: in main chunk
[C]: in ?
stack traceback:
[C]: in ?
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
... (skipping 370 levels)
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
.\raylib.lua:1: in main chunk
[C]: in function 'require'
raylib.lua:1: in main chunk
[C]: in ?
what i do??
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.