x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
any_converter.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\luabind\examples\any_converter\any_converter.cpp
旋转
特效
属性
历史版本
#include
extern "C" { #include "lua.h" #include "lauxlib.h" #include "lualib.h" } bool dostring(lua_State* L, const char* str) { if (luaL_loadbuffer(L, str, std::strlen(str), str) || lua_pcall(L, 0, 0, 0)) { const char* a = lua_tostring(L, -1); std::cout << a << "\n"; lua_pop(L, 1); return true; } return false; } #include
#include
#include
template
struct convert_any { static void convert(lua_State* L, const boost::any& a) { luabind::detail::convert_to_lua(L, *boost::any_cast
(&a)); } }; std::map
any_converters; template
void register_any_converter() { any_converters[&typeid(T)] = convert_any
::convert; } namespace luabind { namespace converters { yes_t is_user_defined(by_value
); yes_t is_user_defined(by_const_reference
); void convert_cpp_to_lua(lua_State* L, const boost::any& a) { typedef void(*conv_t)(lua_State* L, const boost::any&); conv_t conv = any_converters[&a.type()]; conv(L, a); } } } boost::any f(bool b) { if (b) return "foobar"; else return 3.5f; } int main() { register_any_converter
(); register_any_converter
(); register_any_converter
(); register_any_converter
(); lua_State* L = lua_open(); #if LUA_VERSION_NUM >= 501 luaL_openlibs(L); #else lua_baselibopen(L); #endif using namespace luabind; open(L); module(L) [ def("f", &f) ]; dostring(L, "print( f(true) )"); dostring(L, "print( f(false) )"); dostring(L, "function update(p) print(p) end"); boost::any param = std::string("foo"); luabind::call_function
(L, "update", param); lua_close(L); }
any_converter.cpp
网页地址
文件地址
上一页 1/3
下一页
下载
( 1 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.