[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modern Lua binding library
- From: Sean Conner <sean@...>
- Date: Mon, 14 Mar 2016 22:50:37 -0400
It was thus said that the Great ThePhD once stated:
> Dear. Mr. Conner,
>
> My main application is C++, and it embeds lua (though sometimes it
> relinquishes full control to a lua loop), so I needed something a bit
> strong to handle my needs.
>
> Thusly, Yes[1]. Given this lua code:
>
> function f (num_value, a)
> return num_value * 2, a:bark()
> end
> nested = { variables = { no = { problem = 10 } } }
>
> The following code will do (I believe) what you ask for, calling both a
> lua function and a C++ function with the (table-nested) lua variable and
> the C++ variable:
>
> sol::function cpp_bark = lua["f"];
> sol::function lua_bark = lua["g"];
> sol::reference lua_variable_x = lua["nested"]["variables"]["no"]["problem"];
> A cpp_variable_y;
> std::tuple<int, int> cppresult = cpp_bark(lua_variable_x, cpp_variable_y);
> std::pair<int, int> luaresult = lua_bark(lua_variable_x, cpp_variable_y);
>
That's impressive.
-spc (Thanks for the example)
> [1] And here's the code running: http://i.imgur.com/nJDfLHw.png