[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Problems with luaL_checkuserdata
- From: "Tom Miles" <Tom@...>
- Date: Tue, 4 Dec 2007 15:15:18 -0000
I've been trying to add some form of type safety with my use of
representing pointers in my C++ app with lightuserdata, using
lua_newmetatable, and luaL_checkuserdata etc. This works in most
instances, but I have an odd situation that I don't know what to do
I have this code in my script:
local region_details = nil
local map = nil
function InitRegionMap(theatre, faction)
region_details = CampaignUI.RegionsInTheatre(theatre, faction)
map = UIImage(region_details.Map)
The RegionsInTheatre call returns a table of information of which one
field is a value called "Address" that is a userdata storing a pointer
to a "REGION" class, the UIImage is a class wrapped with Lunar, and
Address is a global userdata assigned with a userdata value of type
"COMPONENT". Before I added the checkuserdata, this all worked fine,
when I read out Address in the SetComponentTexture and do a
lua_touserdata() it works fine, however when I use luaL_checkuserdata it
seems to get confused about which "Address" variable is being used.
I.e. it checks the region_details.Address value, not the global value.
The error I get when calling luaL_checkuserdata is:
"calling 'SetComponentTexture' on bad self (COMPONENT expected, got
If I put print("Map", Address) before and after the region_details
assignment, I get:
Map COMPONENT (0x0228f885c)
Map REGION (0x0228f885c)
As far as I know I don't do anything wrong passing tables back to Lua
from my app. Does anyone have any ideas about what's going on here? I'm
using Lua 5.1, and I've already fallen foul of the "no virtual indices"
issue, but can't for the life of me figure out what I'm doing wrong.
Thanks for any help,
This email is sent by The Creative Assembly Limited company No. 03425917, registered in England &Wales registered office 27 Great West Road, Middlesex, TW8 9BW, England. The contents of this e-mail and any attachments are confidential to the intended recipient and may also be legally privileged. Unless you are the named addressee (or authorised to receive for the addressee) of this email you may not copy, disclose or distribute it to anyone else. If you have received this email in error, please notify us immediately by e-mail on email@example.com and then delete the email and any copies. The Creative Assembly Limited have made all reasonable efforts to ensure that this e-mail and any attached documents or software are free from software viruses, but it is the recipient's responsibility to confirm this.