1

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 values from the Userdata?

whatupdave
  • 3,124
  • 5
  • 28
  • 32
  • 1
    I have not used LuaObjcBridge but I have a fair amount of experience with Lua and a custom bridge. I looked at the code and I do not see any support in the metatable to allow access to struct members. It appears that the metatable only tries to bridge objective C methods for full objects.You could try position.x or position.y but it does not look like those would work. In this case you could write your own bridged C functions that would extract the values from the userdata. – Jon Steinmetz Jan 14 '11 at 03:09
  • I wrote a lengthy answer for doing this in c++ by hand. I know its not exactly what you are asking for but it may help. http://stackoverflow.com/questions/3481856/sending-variable-pointers-back-and-forth-between-c-and-lua/3506654#3506654 The only difference would be the way that classes are composed is c++ vs. obj-c – Nick Van Brunt Jan 14 '11 at 20:37

1 Answers1

1

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.

Łukasz Gruner
  • 2,929
  • 3
  • 26
  • 28