lua function as argument in C
- by Nil
I'm going to pass a function to another function which should operate with the passed function. For example:
handler(fun1("foo",2))
handler(fun2(1e-10))
The handler is something like calling the passed function many times.
I'm going to bind handler, fun1, fun2 to C-functions. fun1 and fun2 are going to return some user data with a pointer to some cpp-class so that I can further recover which function was it.
The problem now is that fun1 and fun2 are going to be called before passed to handler. But I don't need this, what I need is the kind of function and its parameters. However, I should be able to call fun1 and fun2 alone without handler:
fun1("bar",3)
fun2(1e-5)
Is it possible to get the context the function is called from?
While typing the question, I realized I could do following
handler(fun1, "foo",2);
handler(fun2, 1e-10);