Lua 5.3 -- SOL2.0 用户指南 【1】

SOL2.2 是一个快速、简单的C++与LUA的绑定器。如果确定要在你的程序里面同时运行Lua和C++,SOL 是一个高性能的绑定器,是一个API使用方便的 GO-TO 框架。

 

简单看一下特点:这个链接到(未链接)大部分API。您也可以直接浏览API或阅读教程。要了解有关usertypes的实现的详细信息,请参阅此处要了解如何处理函数参数,请参阅此注释。看不到你想要的功能?向问题跟踪器发送有关特定抽象支持的请求。

 

下面的代码更多示例可以在examples目录中找到

 

#define SOL_CHECK_ARGUMENTS 1

#include <sol.hpp>
#include "../assert.hpp" int main() { sol::state lua; int x = 0; lua.set_function("beep", [&x]{ ++x; }); lua.script("beep()"); c_assert(x == 1); sol::function beep = lua["beep"]; beep(); c_assert(x == 2); return 0; }

#define SOL_CHECK_ARGUMENTS 1

#include <sol.hpp>
#include "../assert.hpp" struct vars { int boop = 0; int bop () const { return boop + 1; } }; int main() { sol::state lua; lua.new_usertype<vars>("vars", "boop", &vars::boop, "bop", &vars::bop); lua.script("beep = vars.new()\n" "beep.boop = 1\n" "bopvalue = beep:bop()"); vars& beep = lua["beep"]; int bopvalue = lua["bopvalue"]; c_assert(beep.boop == 1); c_assert(lua.get<vars>("beep").boop == 1); c_assert(beep.bop() == 2); c_assert(bopvalue == 2); return 0; }





转载于:https://www.cnblogs.com/oldtom/p/10165900.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值