如何通过SWIG将lua嵌入到c ++中 [英] How to embed lua in c++ via SWIG

查看:111
本文介绍了如何通过SWIG将lua嵌入到c ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一组SWIG封装我的类和它所有的构建。我可以创建一个lua虚拟机,并加载我的包装,但在那一刻,我被挫败。 Googling告诉我如何在luig中把c ++放在swig中,而不是如何把lua放在c ++中。

Currently I have a set of SWIG wrappers for my classes and it all builds. I can create a lua virtual machine and load my wrappers, but at that point I'm flummoxed. Googling tells me how to shove put c++ in lua in swig, but not how to put lua in c++.

真的我想做的是管理实例化一个lua对象并传递给我的主要游戏引擎对象指针,从那里我可以管理

Really all I want to do is manage to instantiate a lua object and pass it my main game engine object pointer, from there I can manage

推荐答案

它在 Lua C API 上有一个部分。

对于调用Lua函数,请使用 lua_pcall ,相当于 lua_call (有一个简短示例),除非它将捕获Lua运行时错误。

For calling Lua functions use lua_pcall, which is equivalent to lua_call (that has a short example) except it will catch Lua runtime errors.

您必须已经加载并运行脚本一次(使用例如 luaL_dofile ),因为第一步是为脚本定义要调用的函数。返回时,您可以使用 lua_getglobal 访问脚本定义的函数。

You must have already loaded and run the script once (using eg. luaL_dofile) since the first step is for the script to define the functions for you to call. When it returns, you can access the script-defined functions with lua_getglobal.

这篇关于如何通过SWIG将lua嵌入到c ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆