Re: sdl2 and ffi

new topic     » goto parent     » topic index » view thread      » older message » newer message
ChrisB said...

Hi Andy

Did you just replace that one instance? There are quite a few others. All surf s and rect s need to be atoms, not sequences, because all of the sdl C functions, afaict, need to have pointers sent to them, and you are trying to send a type. I may be missing something of course.

I've just recloned the repository, and it's wiped all the changes and test files I made on my local folder. Ho hum, back to the drawing board.



edit - I see that define_c_type returns an atom, which I imagine is a pointer to the block of memory allocated for the structure. The structure may need to be filled to be sent, or may be filled by the C function, but on the eu side the function still need to recieve pointers (atoms) to send to the C function of the block of memory allocated.



I'll try and go through the code and update it, this weekend. I think my inital thought process must have been from looking at how Greg wrapped Raylib using FFI.

--Raylib Wrapper (FFI) 
public constant RL_VECTOR2 = define_c_type({ 
	C_FLOAT, -- x   // Vector x component 
	C_FLOAT  -- y   // Vector y component 
export constant raylib = open_dll( "raylib.dll" ), 
	xInitWindow         = define_c_proc( raylib, "+InitWindow", {C_INT,C_INT,C_STRING} ), 
	xWindowShouldClose  = define_c_func( raylib, "+WindowShouldClose", {}, C_BOOL ), 
	xCloseWindow        = define_c_proc( raylib, "+CloseWindow", {} ), 
	xGetWindowPosition  = define_c_func( raylib, "+GetWindowPosition", {}, RL_VECTOR2 ), 
	xGetScreenToWorld2D = define_c_func( raylib, "+GetScreenToWorld2D", {RL_VECTOR2,RL_CAMERA2D}, RL_VECTOR2 ) 
--Only copying what is relevant to my thought process 
public function GetScreenToWorld2D( sequence position, sequence camera ) 
	return c_func( xGetScreenToWorld2D, {position,camera} ) 
end function 

My thought process being that if a struct or so is defined as define_c_type() using FFI, then it must be called as a sequence in Euphoria. However that it is clear that is not always the case. SDL must not pass all structs by value as Raylib does.

public constant SDL_Rect = define_c_type({ 
--Part of My SDL Wrapper 
--From SDL_Rect.e 
	C_INT, --x 
	C_INT, --y 
	C_INT, --w 
	C_INT --h 
export constant xSDL_HasIntersection = define_c_func(sdl,"+SDL_HasIntersection",{SDL_Rect,SDL_Rect},C_BOOL) 
public function SDL_HasIntersection(sequence a,sequence b) 
	return c_func(xSDL_HasIntersection,{a,b}) 
end function 
--My thought being you could use it as such: 
sequence myRect = SDL_Rect() 
myRect[1] = 5 --x 
myRect[2] = 5 --y 
And so forth.  

My thought process being that sequence is the closest thing Euphoria has to struct in its current form.

EDIT: I have changed most of the sequences to atoms. Functions that returned a define_c_type() should now return a pointer as I changed it from I.E. SDL_Rect to C_POINTER.

new topic     » goto parent     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu