- 博客(0)
- 资源 (1)
- 收藏
- 关注
LuaHelper绑定助手
可以方便的将lua嵌入c++程序<br>能高效的存取lua变量<br>方便使用c++类扩展lua功能<br>支持 c++对象指针参数,返回值等等<br><br>//CreateClass<类型>([是否生成析构函数(默认=true)])<br> //Constructor<参数列表>([可选]构造函数名<lua不支持重载>)<br> //CreateMethod<返回值类型>(函数名,函数指针)<br> //CreateStaticMethod<返回值类型>(函数名,函数指针)<br> //默认生成释放函数Free<br> LContext.CreateClass<test2>()<br> .Constructor();<br> LContext.CreateClass<test>()<br> .Constructor()<br> .Constructor<test2*>("test_ptr")<br> .Constructor<int>()<br> .Constructor<const char*>("test_str")<br> .Constructor<int,int>()<br> .CreateMethod<int>("fn",test::fn)<br> .CreateMethod<int>("fn2",test::fn2)<br> .CreateMethod<void>("fn3",test::fn3)<br> .CreateMethod<void>("fn4",test::fn4)<br> .CreateStaticMethod<void>("test_fn",test_fn);//注册类静态方法<br> LContext.CreateStaticMethod<void>("test_fn",test_fn);<br> LContext.CreateStaticMethod<int>("test_fn2",test_fn2);<br> LContext.CreateStaticMethod<void>("test_fn5",test_fn5);<br> LContext.CreateStaticMethod<int>("test_fn6_with_ret",test_fn6_with_ret);<br> LContext.CreateStaticMethod<void>("test_fn6_with_object_param",test_fn6_with_object_param);<br> LContext.CreateStaticMethod<int>("fn5",test::fn5);<br> LContext.CreateStaticMethod<test2*>("test_return_object",test_return_object);<br>................<br><br>//测试类静态方法<br> LContext.GetVariable("test:test_fn").Invoke();<br><br> LContext.GetVariable("test_fn").Invoke();<br> LContext.GetVariable("test_fn5").Invoke(0,0,0,0,0);<br> LContext.GetVariable("test_fn6_with_object_param").Invoke(<est2);<br> int kl = LContext.GetVariable("test_fn6_with_ret").InvokeWithReturn<int>(19201,0,0,0,0);<br>......................<br><br>//返回c++对象到Lua测试<br> test2* pp2 = LContext.GetVariable("test_return_object").InvokeWithReturn<test2*>(<est2);<br> if(pp2->i != LTest2.i) throw "Error.";<br> //返回c++对象到Lua测试<br> if(!LContext.DoString("v2 = test2:test2();"))<br> printf("%s",LContext.GetLastError());<br> if(!LContext.DoString("print(v2);vv3 = test_return_object(v2);print(vv3);"))<br> printf("%s",LContext.GetLastError());<br> pp2 = LContext.GetVariable("vv3").ToObject<test2*>();<br> if(pp2->i != LTest2.i) throw "Error";
2008-05-20
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人