将C结构指针传递给lua脚本 [英] Passing C struct pointer to lua script

查看:111
本文介绍了将C结构指针传递给lua脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道有没有一种方法可以将结构指针传递给lua脚本, 并从lua到达其成员而无需复制(出于读写目的).

I would like to know is there a way to pass a struct pointer to a lua script, and reach it's members from lua without copy (for read and write purposes).

例如,是否有可能直接通过其指针覆盖c结构的成员?

So, for example is it possible to overwrite a member of a c struct directly through of its pointer?

(我正在使用luajit)

(I am using luajit)

推荐答案

看到已经为luajit标记了此标记,可以将轻量用户数据(如其他人所提到的)与FFI结合使用,以直接访问结构成员,请参见此处的教程. : http://luajit.org/ext_ffi_tutorial.html

Seeing as you have tagged this for luajit, you can combine the light userdata (as mentioned by others) with FFI for direct struct member access, see the tutorial here: http://luajit.org/ext_ffi_tutorial.html

这篇关于将C结构指针传递给lua脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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