Re: ffi cdef hash table

  • From: Mike Pall <mike-1503@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 16 Mar 2015 22:31:44 +0100

Mike Stefaniak wrote:
> Is there any way to declare hash table based data structure, that would say
> have a key of string, and a value of an array of doubles? I do not know the
> keys to store at compile time and can't have a well defined c struct.

Well, the FFI is a low-level API. You'd have to code all of the
hash table management yourself and then deal with the garbage
collector, too.

But ... strings as keys is a perfect use case for a plain Lua
table, which is really a hash table under the hood. And the code
has been heavily optimized already.

Simply turn C strings to Lua strings with ffi.string() and then
use them as keys for a Lua table. You can store an ffi array of
doubles as a value (or whatever object you need).

--Mike

Other related posts: