lua-users home
lua-l archive

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


You use the API function lua_call and its cousins to call a function you have on the stack. As far as saving it in C land, I don't think you can export it across the API barrier; someone please correct me if I'm wrong. If you do need a persistent handle to it for future use, what you can do is put it in the registry (basically a globally-available table for use by clients of the Lua API).

On Tue, Jun 2, 2015 at 4:26 PM, Laurent FAILLIE <l_faillie@yahoo.com> wrote:
Hello,

I'm working on a C programs using Lua as embedded language.

At Lua side, I'm defining a table on witch a filed need to be a function as :

_, err = Broker:subscribe {
        { topic = "/tata", function = myfunc },
        { topic = "tutu", function = func2 }
}

And I know at C side I have to look up for TFUNCTION for "function" field.
My reading function is creating a structure containing
- a string, the topic,
- and a "reference" or something to keep track of the function

now my question :
1/ How can I store TFUNCTION at C side ?
2/ How my C code can "call" this Lua function ?

If it's not so clear, please have a look on my code here : https://github.com/destroyedlolo/Selene/blob/master/src/MQTT.c
especially on line 79.

Thanks

Laurent

---
The misspelling master is on the Web.
  _________ 100 % Dictionnary Free !
/               /(
/ Dico       / / Pleins d'autres fautes sur
/________/ /
(#######( / http://destroyedlolo.info
Quoi, des fautes d'orthographe! Pas possible ;-D.



--
Brigham Toskin