|
If you are REALLY memory constrained you could store the information in a userdata and provide helper C functions to extract portions of it (in effect, treating it as an array. You mentioned userdata as being complex; it really isn't: Full userdata (the original version) is just a block of memory allocated for you by Lua, and stored in a Lua value. The C Api provides a way to access that memory block, and so in C you can treat it like a normal heap allocated block of memory (except that you cannot free it, that is Luas job). Light userdata is just Lua keeping a wrapper to a C pointer; you must allocate the memory, and free it when no longer needed (and make sure Lua has no stray pointers left). In either case, you keep the array in the userdata and write a couple of C functions that you can call from Lua to access elements of the array (get/set, probably all you need). You will need to understand the Lua stack, but that's not all that hard, PiL does a good job of explaining it. If you want to be really fancy, and you use full userdata, you can even attach a metatable, override __index, and then you can use Lua [] syntax to access the array (read only). --Tim |