Re: Manage C structures

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

Before it gets deprecated by libffi, here is another release in pure Euphoria: http://jean-marc.duro.pagesperso-orange.fr/Structures_v0.2.0_2022-09-26.zip

It can read or write individual items in addition to writing or reading whole simple structures.

include std/dll.e 
include std/machine.e 
include std/console.e 
include common.e 
include structs.e 
 
sequence myStructure =  
"struct _mydata {" & 
"  pointer a;" & 
"  float b;" & 
"  char c;" & 
"} bar;" 
 
f_debug = open("debug.log", "w") 
debug_level = DEBUG 
 
sequence struct = allocateStructure(myStructure) 
writeStructure(struct, {allocate_string("A string"), 25.2, 'a'} ) 
sequence s = readStructure(struct) 
printf(1, "%s = \"%s\", %s = %4.1f, %s = '%s'\n", { 
  struct[SU_DEF][1][VAR_NAME], peek_string(s[1]), 
  struct[SU_DEF][2][VAR_NAME], s[2], 
  struct[SU_DEF][3][VAR_NAME], s[3] 
}) 
writeVariable(struct, "b", 40.0) 
s = readStructure(struct) 
atom b = readVariable(struct, "b") 
printf(1, "b = %4.1f\n", {b}) 
printf(1, "%s = \"%s\", %s = %4.1f, %s = '%s'\n", { 
  struct[SU_DEF][1][VAR_NAME], peek_string(s[1]), 
  struct[SU_DEF][2][VAR_NAME], s[2], 
  struct[SU_DEF][3][VAR_NAME], s[3] 
}) 
freeStructure(struct) 
 
close(f_debug) 
maybe_any_key() 

a = "A string", b = 25.2, c = 'a' 
b = 40.0 
a = "A string", b = 40.0, c = 'a' 
Press Any Key to continue... 

Jean-Marc

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

Search



Quick Links

User menu

Not signed in.

Misc Menu