Re: Preliminary libffi progress
- Posted by jmduro Sep 26, 2022
- 1636 views
Icy_Viking said...
This might work better than having a struct function. Though I do think Euphoria would benefit from a struct type of some kind.
If you wish to compare, here is a version without libffi that can run the core_basic_windows.ex demo:
include std/dll.e include std/machine.e include structs.e public constant LIGHTGRAY = { 200, 200, 200, 255 } -- Light Gray ------------------------------------------------------------------------------------ -- Structures Definition ------------------------------------------------------------------------------------ -- Vector2, 2 components public sequence RL_VECTOR2 = "typedef struct Vector2 {" & " float x;" & -- Vector x component " float y;" & -- Vector y component "} Vector2;" -- Vector3, 3 components public sequence RL_VECTOR3 = "typedef struct Vector3 {" & " float x;" & -- Vector x component " float y;" & -- Vector y component " float z;" & -- Vector z component "} Vector3;" -- Color, 4 components, R8G8B8A8 (32bit) public sequence RL_COLOR = "typedef struct Color {" & " unsigned_char r;" & -- Color red value " unsigned_char g;" & -- Color green value " unsigned_char b;" & -- Color blue value " unsigned_char a;" & -- Color alpha value "} Color;" sequence Vector2 = allocateStructure(RL_VECTOR2) sequence Vector3 = allocateStructure(RL_VECTOR3) sequence Color = allocateStructure(RL_COLOR) constant raylib = open_dll( "raylib.dll" ), xInitWindow = define_c_proc( raylib, "+InitWindow", {C_INT,C_INT,C_POINTER} ), xWindowShouldClose = define_c_func( raylib, "+WindowShouldClose", {}, C_BOOL ), xCloseWindow = define_c_proc( raylib, "+CloseWindow", {} ), xGetWindowPosition = define_c_func( raylib, "+GetWindowPosition", {}, C_POINTER ), xSetTargetFPS = define_c_proc( raylib, "+SetTargetFPS", {C_INT} ), xClearBackground = define_c_proc( raylib, "+ClearBackground", {C_POINTER} ), xBeginDrawing = define_c_proc( raylib, "+BeginDrawing", {} ), xEndDrawing = define_c_proc( raylib, "+EndDrawing", {} ), xDrawText = define_c_proc( raylib, "+DrawText", {C_POINTER,C_INT,C_INT,C_INT,C_POINTER} ), $ public procedure InitWindow( integer width, integer height, sequence title ) c_proc( xInitWindow, {width,height,allocate_string(title)} ) -- title string is allocated/freed automatically end procedure public function WindowShouldClose() return c_func( xWindowShouldClose, {} ) end function public procedure CloseWindow() c_proc( xCloseWindow, {} ) end procedure public function GetWindowPosition() free(Vector2[SU_ADDRESS]) Vector2[SU_ADDRESS] = c_func( xGetWindowPosition, {} ) -- returns {x,y} return readStructure(Vector2) end function public procedure SetTargetFPS( integer fps ) c_proc( xSetTargetFPS, {fps} ) end procedure public procedure ClearBackground( sequence color ) writeStructure(Color, color ) c_proc( xClearBackground, Color[SU_ADDRESS] ) -- color is {r,g,b,a} end procedure public procedure BeginDrawing() c_proc( xBeginDrawing, {} ) end procedure public procedure EndDrawing() c_proc( xEndDrawing, {} ) end procedure public procedure DrawText( sequence text, integer posX, integer posY, integer fontSize, sequence color ) writeStructure(Color, color ) c_proc( xDrawText, {allocate_string(text),posX,posY,fontSize,Color[SU_ADDRESS]} ) end procedure