How to create a function object compatible with C ++ in LUA?

I am thinking about how to create my own APIs, I plan to have a C ++ application with a script level in LUA.

For a few key points in my design, I would like to enable the user to create a function object that represents what he wants to do in the LUA, rather than send this function object from the LUA to C / C ++.

In pseudo code, in C ++ I have class T

class T {
...
int num1 = 0;
float num2 = 0.0f;
std::string str{"NONE"};
...
};

And I would like to process the instance Twith the help function objectprovided from the LUA, in this way

void applyFunc(T t,F f){
f(t);
}

The problem is that I cannot find anything in the LUA that creates a function object, such as C ++ 11 lambda or std::function, or any other object that can be thought of as a function object.

, : , ++, LUA?

+4
1

, LUA, , lambda std:: function ++ 11 , .

, function. . ++ ++.

:

void applyFunc(T t,F f){  
   f(t);  
}  

: ++ Lua userdata Lua. , Lua ++.

, Lua , , ++ Lua. , .

, ++. ( ), , , .

Google " ++ Lua __index", . , .

+1

Source: https://habr.com/ru/post/1528189/


All Articles