CDATA as table keys

  • From: Meae Flowright <scratchnloved@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 11 Nov 2014 07:48:20 -0500

I'm writing server software for a game in luajit, and using lua objects to
represent items, entities and similar concepts in-game.
I'm using objects by identity, not value ({}~={}).

--an example
reg=reg or {} --item registry

reg[11]={
 name='iron sword'
}
reg[12]={
 name='gold coin'
}

player_obj[ reg[12] ] = 100     --give player 100 coins
player_obj.right_hand = reg[11] --put sword in player's right hand



http://luajit.org/ext_ffi_semantics.html#cdata_key
I'd like to use c structs/unions as objects for memory savings, but this
segment suggests that's not viable for c values.
Am I safe to use structs or unions as objects? Do I need to worry about the
address changing spontaneously, or similar structs re-using an address?

Thanks in advance,

-Meae

Other related posts: