forum-msg-id-137267-edit

Original date:2022-11-19 07:47:55 Edited by: ChrisB Subject: Re: sdl2 and ffi

Hi

There's a rule in there somewhere isn't there.

When the C library accepts pass by value you can pass the parameter as a sequence, eg

public constant RL_VECTOR2 = define_c_type({  
	C_FLOAT, -- x   // Vector x component  
	C_FLOAT  -- y   // Vector y component  
})  
 
constant xGetScreenToWorld2D = define_c_func( raylib, "+GetScreenToWorld2D", {RL_VECTOR2,RL_CAMERA2D}, RL_VECTOR2 )  
--Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position 
 
public function GetScreenToWorld2D( sequence position, sequence camera )  
	return c_func( xGetScreenToWorld2D, {position,camera} )  
end function  

However, when the C library accepts pass by reference, you must use the pointer to the structure as a parameter, eg

public constant SDL_Rect = define_c_type({  
	C_INT, --x  
	C_INT, --y  
	C_INT, --w  
	C_INT --h  
})  
 
--to illustrate the 2 ways of filling the structure 
a = allocate_structure(SDL_Rect) 
b = allocate_structure(SDL_Rect, {30,70,10,10}) 
 
poke4(a, {20,30,50,50} ) 
 
export constant xSDL_HasIntersection = define_c_func(sdl,"+SDL_HasIntersection",{SDL_Rect,SDL_Rect},C_BOOL)  
--SDL_bool SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B);  
 
public function SDL_HasIntersection(atom a,atom b)  
        --a and b pointers to the SDL_RECT structures, already filled with values poked into the allocated memory blocks 
	return c_func(xSDL_HasIntersection,{a,b})  
end function  
 

Does that look ok to add to some documentation?

Chris

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu