用C跟踪的Lua表 [英] Tracking Lua tables in C

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

问题描述

我有C ++对象,我有 Lua的对象/表。 (也有痛饮 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 ::更新将有以下code:

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!!

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

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