10 bool dostring(lua_State
* L
, const char* str
)
12 if (luaL_loadbuffer(L
, str
, std::strlen(str
), str
) || lua_pcall(L
, 0, 0, 0))
14 const char* a
= lua_tostring(L
, -1);
15 std::cout
<< a
<< "\n";
22 #define LUABIND_NO_HEADERS_ONLY
24 #include <luabind/luabind.hpp>
25 #include <boost/any.hpp>
30 static void convert(lua_State
* L
, const boost::any
& a
)
32 typename
luabind::detail::default_policy::template generate_converter
<T
, luabind::detail::cpp_to_lua
>::type conv
;
34 conv
.apply(L
, *boost::any_cast
<T
>(&a
));
38 std::map
<const std::type_info
*, void(*)(lua_State
*, const boost::any
&)> any_converters
;
41 void register_any_converter()
43 any_converters
[&typeid(T
)] = convert_any
<T
>::convert
;
50 yes_t
is_user_defined(by_value
<boost::any
>);
51 yes_t
is_user_defined(by_const_reference
<boost::any
>);
53 void convert_cpp_to_lua(lua_State
* L
, const boost::any
& a
)
55 typedef void(*conv_t
)(lua_State
* L
, const boost::any
&);
56 conv_t conv
= any_converters
[&a
.type()];
64 if (b
) return "foobar";
70 register_any_converter
<int>();
71 register_any_converter
<float>();
72 register_any_converter
<const char*>();
73 register_any_converter
<std::string
>();
75 lua_State
* L
= lua_open();
78 using namespace luabind
;
86 dostring(L
, "print( f(true) )");
87 dostring(L
, "print( f(false) )");
88 dostring(L
, "function update(p) print(p) end");
90 boost::any param
= std::string("foo");
92 luabind::call_function
<void>(L
, "update", param
);