跟踪Lua表在C [英] Tracking Lua tables in C

查看:120
本文介绍了跟踪Lua表在C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C ++物件,我有 Lua 物件/表。 (也有 SWIG C ++绑定。)

I have C++ objects and I have Lua objects/tables. (Also have SWIG C++ bindings.)

我需要做的是关联这两个对象,如果我这么说

What I need to be able to do is associate the two objects so that if I do say

CObject* o1 = getObject();
o1->Update();

它将执行相同的Lua:

it will do the equivalent Lua:

myluatable1.Update();

到目前为止,我可以想象CObject :: Update会有以下代码:

So far I can imagine that CObject::Update would have the following code:

void CObject::Update(){
    // Acquire table.

    // ???

    // Do the following operations on the table.
    lua_getfield(L, -1, "Update");
    lua_pcall(L, 0, 0, 0);
}

如何存储/设置要使用的Lua表,请在上面的 // 中使更新调用工作?

How would I store/set the Lua table to be used, and what would go in the // ??? above to make the Update call work?

推荐答案

我不敢相信没有人注意到这个!

I cant believe nobody noticed this!

http://www.lua.org/pil/27.3.2.html

Lua API的一部分,用于存储对lua对象和表的引用并返回引用,以便存储在C结构中!

A section of the Lua API for storing references to lua objects and tables and returning references for the purposes of being stored in C structures!!

这篇关于跟踪Lua表在C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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