How to wrap a C function whose parameters are pointer to structs, so that it can be called from Lua?

I have the follwing C function. How should I wrap it so it can be called from a Lua script? typedef struct tagT{ int a ; int b ; } type_t; int lib_a_f_4(type_t *t) { return t->a * t->b ; } I know how to wrapr it if the function parameter type were `int` or `char *`. Should I use `table` type for a C structure? EDIT: I am using SWIG for the wraping , according to this [doc][1], It seems that I should automatically have this function `new_type_t(2,3)` , but it is not the case. > If you wrap a C structure, it is also > mapped to a Lua userdata. By adding a > metatable to the userdata, this > provides a very natural interface. For > example, > > `struct Point{ int x,y; };` > > is used as follows: > > `p=example.new_Point()` > `p.x=3` > `p.y=5` > `print(p.x,p.y) 3 5` > > > Similar access is provided for unions > and the data members of C++ classes. C > structures are created using a > function new_Point(), but for C++ > classes are created using just the > name Point(). [1]: http://www.swig.org/Doc1.3/Lua.html

以上就是How to wrap a C function whose parameters are pointer to structs, so that it can be called from Lua?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏