Roman Glebenkov
2014-07-23 20:36:44 UTC
Hello.
I am starting to get into FFI and have been successful to a degree.
However, I can't figure out how to make a 2-dimensional structure that can
contain multiple sub-structures
So, for example, right now I have a table called 'world', which contains
several sub-tables, namely 'blocks', 'backgrounds', 'trees', 'stillWater',
'movingWater' and and integer 'treeCount', in code it looks like this:
world = {}
world.blocks = {}
world.trees = {}
world.backgrounds = {}
world.stillWater = {}
world.movingWater = {}
My question is, how would I turn all of this in a C structure, with the
structures being accessable via [x][y] indexes. For reference, here's what
I managed to make use of FFI as of now:
ffi.cdef[[
typedef struct {uint8_t n, h; bool p;} block_t;
]]
world = {}
world.blocks = {}
world.blocks[x] = {}
world.blocks[x][y] = ffi.new('world_t", 1)
^ and so on for trees, backgrounds, stillWater, movingWater, etc.
Ideally, I want to turn the 'world' table into a pure C structure, but have
no idea how. Any help would be greatly appreciated.
Thanks in advance.
I am starting to get into FFI and have been successful to a degree.
However, I can't figure out how to make a 2-dimensional structure that can
contain multiple sub-structures
So, for example, right now I have a table called 'world', which contains
several sub-tables, namely 'blocks', 'backgrounds', 'trees', 'stillWater',
'movingWater' and and integer 'treeCount', in code it looks like this:
world = {}
world.blocks = {}
world.trees = {}
world.backgrounds = {}
world.stillWater = {}
world.movingWater = {}
My question is, how would I turn all of this in a C structure, with the
structures being accessable via [x][y] indexes. For reference, here's what
I managed to make use of FFI as of now:
ffi.cdef[[
typedef struct {uint8_t n, h; bool p;} block_t;
]]
world = {}
world.blocks = {}
world.blocks[x] = {}
world.blocks[x][y] = ffi.new('world_t", 1)
^ and so on for trees, backgrounds, stillWater, movingWater, etc.
Ideally, I want to turn the 'world' table into a pure C structure, but have
no idea how. Any help would be greatly appreciated.
Thanks in advance.