开发者

Lua: Calling c method that returns userdata to Lua

开发者 https://www.devze.com 2023-02-03 23:11 出处:网络
Im using LuaObjcBridge and I\'m calling a method from Lua like this: local position = owner:position()

Im using LuaObjcBridge and I'm calling a method from Lua like this:

local position = owner:position()

In objective-c this returns a CGPoint struct with X and Y which the bridge converts into Userdata. So CGPoint struct -> Lua userdata. In Lua how would I access the X and Y 开发者_JAVA百科values from the Userdata?


you need to:

  • define metatable, that contains methods that operate on userdata
  • set metatable on userdata
  • set the same metatable as __index field on userdata

or:

  • set some methods that operate on userdata
  • expose them to Lua

look at http://www.lua.org/pil/28.1.html

userdata can't do anything by itself, you need to add methods that do something with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消