lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,
I'm wanting to use Lua's Light User Data functionality to prototype
some data processing routines.  I'm basically dealing with a pointer
to raw memory and a header struct that describes the memory layout.
It looks something like this in C:

char *memory_in;
t_mem_header *memory_in_header;

char *memory_out;
t_mem_header *memory_out_header;

What I want to do is pass all 4 of these pointers to lua in as light
user data.  Allocation and deallocation of this memory is handled by
the app.  Typical C usage of this goes as follow:

void process_data(t_mem_header *memory_in_header, char *memory_in,
t_mem_header *memory_out_header, char *memory_out)
{
   /*
       leaving out stuff like variable declarations
  */

     for(j=0; j < height; j++) {
           for(i=0; i < width; i++) {
                 //process input and put result in output
             }
     }
}


Now, the data can be many flavors like uchar, long, float, or double.
I'd like to use Lua to replace the double for loops such that I can
load little processing scripts and see how things work and when I get
something that works well I would then most likely go back to C and
hard code it.  A secondary motive for doing this is to get to know Lua
more and just try some ideas out.  I've looked around for some info
and examples on uses of Light User Data, but I'm still not sure
exactly where to start.  How do I go about writing Lua functions that
process the Light User Data such that I can script the processing?

As a simple starter, how would I recreate the following:
*(float *)(memory_out + j*width + i) =  1.0 + *(float *)(memory_in+
j*width + i);

thanks,
wes