lua-users home
lua-l archive

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



On 26-Oct-06, at 11:10 AM, jdarling@eonclash.com wrote:

I know I've seen this answer here some place, but I can't find it in my
searchs (proto, lua, callback, function, cfunction).  I have a script
that defines a callback to be called by source method being called by
the script.  Ok that makes no sense, so lets try some sample source:

:SCRIPT:
v = {[1]='Hello', [2]='World', [3], '!'}
function foo(i)
  print(v[i]..' ')
end

TestCallback(table.getn(v), foo)
:ENDSCRIPT:

Now TestCallback is defined in my source code and recieves the getn(v)
fine (3 in this case) it then attempts to store the method pointer for
foo (I thought it would be cfunction type, but its proto) of course
this doesn't work for calling later on.  So how can I store the proto
and use it later?  I'm guessing that proto means prototype or method
prototype, but can't find any info on using it or what the structure
looks like.

You have to store it in some Lua structure, probably a table.

Often people do this with luaL_reg, but you could just store it directly in the registry using some known key.