FFI Library is Gold!

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

Hey all,

So I wanted to see how much Greg's FFI Euphoria library would help with wrapping SFML. To my surprise it has helped a lot. For example

--Wrapper Code 
include std/ffi.e 
include Window.e 
 
public constant sfVideoMode = define_c_struct({ 
	C_UINT, --width 
	C_UINT, --height 
	C_UINT --bitsPerPixel 
}) 
export constant xsfRenderWindow_create = define_c_func(gfx,"+sfRenderWindow_create",{sfVideoMode,C_STRING,C_UINT32,C_POINTER},C_POINTER) 
 
public function sfRenderWindow_create(sequence mode,sequence title,atom style,atom set) 
	return c_func(xsfRenderWindow_create,{mode,title,style,set}) 
end function 
--Simple Example 
include std/ffi.e 
 
include System.e 
include Window.e 
include Event.e 
include Graphics.e 
 
sequence mode = {1024,720,32} --width,height,-bitsPerPixel 
 
atom win = sfRenderWindow_create(mode,"Simple Example",sfClose,0) 
 
atom evt = allocate_struct(sfEvent) 
atom evt_type = 0 
 
sfRenderWindow_setFramerateLimit(win,60) 
 
while sfRenderWindow_isOpen(win) do 
	while sfRenderWindow_pollEvent(win,evt) do 
		evt_type = peek_type(evt,C_INT) 
		if evt_type = sfEvtClosed then 
			sfRenderWindow_close(win) 
		end if 
	end while 
	sfRenderWindow_clear(win,sfBlack) 
	sfRenderWindow_display(win) 
end while 
 
sfRenderWindow_destroy(win) 

Not all of my code is shown, but I'm sure from what I've posted, you can notice the changes compared to how my old wrapper was written. I mostly did this as a test and out of boredom. I'm not sure how much I'll continue it, but I may. Also, the FFI library has proven to be coding gold, special thanks to Greg for making it.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu