Re: SDL2 libraries

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

It was just a draft. Here is the very small part that had been done:

ag_gui.e

include std/dll.e 
include std/machine.e 
include std/os.e 
 
atom ag_gui 
 
ifdef WINDOWS then 
  ag_gui = open_dll("../bin/win32/ag_gui.dll") 
elsifdef UNIX then 
  sequence un = uname() 
  sequence arch = un[5] 
  if equal(arch, "i686") then 
    ag_gui = open_dll("../bin/i686/libag_gui.so.5.0.0") 
  elsif equal(arch, "x86_64") then 
    ag_gui = open_dll("../bin/x86_64/libag_gui.so.5.0.0") 
  end if 
end ifdef 
if ag_gui = -1 then 
  puts(1,"Could not open ag_gui library!\n") 
  abort(0) 
end if 
 
constant 
  xAG_WindowNew = define_c_func(ag_gui, "AG_WindowNew", {C_UINT}, C_POINTER), 
  xAG_InitGraphics = define_c_func(ag_gui, "AG_InitGraphics", {C_POINTER}, C_INT), 
  xAG_LabelNew = define_c_func(ag_gui, "AG_LabelNew", {C_POINTER, C_UINT, C_POINTER}, C_POINTER), 
  xAG_WindowShow = define_c_proc(ag_gui, "AG_WindowShow", {C_POINTER} ) 
 
public function AG_WindowNew(integer n) 
  return c_func(xAG_WindowNew, {n}) 
end function 
 
public function AG_InitGraphics(atom win) 
  return c_func(xAG_InitGraphics, {win}) 
end function 
 
public function AG_LabelNew(atom win, integer b, sequence s) 
  atom addr, ret 
   
  addr = allocate_string(s) 
  ret = c_func(xAG_LabelNew, {win, b, addr}) 
  free(addr) 
  return ret 
end function 
 
public procedure AG_WindowShow(atom win) 
  c_proc(xAG_WindowShow, {win}) 
end procedure 

ag_core.e

include std/dll.e 
include std/machine.e 
include std/os.e 
 
atom ag_core 
 
ifdef WINDOWS then 
  ag_core = open_dll("../bin/win32/ag_core.dll") 
elsifdef UNIX then 
  sequence un = uname() 
  sequence arch = un[5] 
  if equal(arch, "i686") then 
    ag_core = open_dll("../bin/i686/libag_core.so.5.0.0") 
  elsif equal(arch, "x86_64") then 
    ag_core = open_dll("../bin/x86_64/libag_core.so.5.0.0") 
  end if 
end ifdef 
if ag_core = -1 then 
  puts(1,"Could not open ag_core library!\n") 
  abort(0) 
end if 
 
public constant 
  xAG_InitCore = define_c_func(ag_core, "AG_InitCore", {C_POINTER, C_UINT}, C_INT), 
  xAG_EventLoop = define_c_func(ag_core, "AG_EventLoop", {}, C_INT), 
  xAG_GetErrorCode = define_c_func(ag_core, "AG_GetErrorCode", {}, C_POINTER), 
  xAG_GetError = define_c_func(ag_core, "AG_GetError", {}, C_POINTER) 
 
 
-- Core 
 
public function AG_InitCore(object progname, integer flags) 
  atom addr, ret 
   
  if sequence(progname) then 
    addr = allocate_string(progname) 
  else 
    addr = progname 
  end if 
  ret = c_func(xAG_InitCore, {progname, flags}) 
  return ret 
end function 
 
public function AG_EventLoop() 
  return c_func(xAG_EventLoop, {}) 
end function 
 
public function AG_GetErrorCode() 
  return c_func(xAG_GetErrorCode, {}) 
end function 
 
public function AG_GetError() 
  return c_func(xAG_GetError, {}) 
end function 

hello.ex

include std/dll.e 
include ../include/ag_core.e 
include ../include/ag_gui.e 
 
  if (AG_InitCore(NULL, 0) = -1) or 
     (AG_InitGraphics(0) = -1) then 
    printf(2, "Init failed: %s\n", {AG_GetError()}) 
    abort (1) 
  end if 
 
  atom win = AG_WindowNew(0) 
  AG_LabelNew(win, 0, "Hello, world!") 
  AG_WindowShow(win) 
  AG_EventLoop() 

Jean-Marc

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

Search



Quick Links

User menu

Not signed in.

Misc Menu