Re: n-dimensional structures via FFI

  • From: Mike Pall <mike-1407@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 24 Jul 2014 14:27:29 +0200

Roman Glebenkov wrote:
> local test = ffi.typeof([[struct {
>     block_t blocks[$][$];
>     tree_t trees[$][$];
>     back_t backgrounds[$][$];
>     water_t stillWater[$][$];
>     water_t movingWater[$][$];
>     }]], 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
> 
> print(test.blocks)
> 
> and it doesn't work, it's saying that the structure has no member named
> 'blocks'.

ffi.typeof returns a type. You need to instantiate it (call it) to
get an actual struct:

  ...
  local test_t = ffi.typeof( ... ... )
  local test = test_t()
  print(test.blocks)

--Mike

Other related posts: