Re: Preliminary libffi progress

new topic     » goto parent     » topic index » view thread      » older message » newer message
ghaberek said...
Icy_Viking said...
jmduro said...
ghaberek said...

It looks like you're allocating the structures to memory and then passing the pointer around. Raylib is passing structures by value. Does this work? Have you tried it with Raylib? Are you using 32-bit or 64-bit Euphoria?

I tried it with Raylib on OEU 4.1 Windows 32-bit. I get a full list of messages with no error but it seems to open a window and close it immediatly after instead of waiting for the user to close the window.

I have the same issue.

Alright, I did some testing using 32-bit Euphoria 4.1 and Raylib. I think the problem might be that libffi isn't setting the return value memory to NULL before making the call, and since I told it C_BOOL was an unsigned int (4-bytes) it was returning the garbage in the upper three bytes of the value, so I'd see something like 0x43542100 come back for "false" which Euphoria rightfully treated as non-zero "true" so the the while loop exited right away. I changed C_BOOL to char value (one byte) instead and that seems to have helped. I also fixed the incorrect ifdef for x86 detection and added a couple more examples that utilize various structure-by-value functions.

-Greg

Excellent work Greg! It works! I can help to finish the Raylib wrapper if you'd like. I'd of course push updates to my local repository then you can merge them later if you wanna. I'll be playing around with the examples and seeing what FFI can do.

EDIT: Here's my fork of Greg's repoistory, I'll be using it as a playground for testing/coding for now: https://github.com/gAndy50/libffi-euphoria

Hopefully this will help Greg as well.

--Raylib's Keyboard Input example in Eu code  
 
include raylib.e 
 
procedure main() 
 
 integer screenWidth = 800 
 integer screenHeight = 600 
  
 InitWindow(screenWidth,screenHeight,"Keyboard Input Example") 
  
 sequence ballPos = {screenWidth / 2, screenHeight / 2} 
  
 SetTargetFPS(60) 
  
 while not WindowShouldClose() do 
  
    --BallPos [1] -is X position, [2] -is Y position 
    if IsKeyDown(KEY_RIGHT) then 
    	ballPos[1] += 2.0 
    	elsif IsKeyDown(KEY_LEFT) then 
    		ballPos[1] -= 2.0 
    end if 
     
	if IsKeyDown(KEY_UP) then 
		ballPos[2] -= 2.0 
		elsif IsKeyDown(KEY_DOWN) then 
			ballPos[2] += 2.0 
	end if 
	 
	--Keep the ball from going off the screen 
	if ballPos[1] <= 0 then 
		ballPos[1] += 2.0 
		elsif ballPos[1] + 50 >= screenWidth then 
			ballPos[1] -= 2.0 
	end if 
	 
	if ballPos[2] <= 0 then 
		ballPos[2] += 2.0 
		elsif ballPos[2] + 50 >= screenHeight then 
			ballPos[2] -= 2.0 
	end if 
  
    BeginDrawing() 
     
	ClearBackground(RAYWHITE) 
	 
    DrawText("Move the ball with arrow keys", 10,10,20, DARKGRAY) 
     
    DrawCircleV(ballPos,50,MAROON) 
     
    EndDrawing() 
 	 
 end while 
  
 CloseWindow() 
	 
end procedure 
 
main() 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu