Jump to content

setmetatable/getmetatable are invalid?


Followers 0

Recommended Posts

@fm34 and I spent some time debugging a cartridge of his. After a while, he narrowed it down to the usage of setmetatable and getmetatable in a table deepcopy function. I'm certain that I've seen setmetatable and getmetatable used before.

 

Why has it stopped working?

Edited by Hügh
Link to comment

For context, the following cartridge is "valid" and compiles correctly...

 

require "Wherigo"

ZonePoint = Wherigo.ZonePoint
Distance = Wherigo.Distance
Player = Wherigo.Player

_cartridge = Wherigo.ZCartridge()

_cartridge.Id = "00000000000000000000000000001337"
_cartridge.Name = "Sandbox"
_cartridge.Activity = "Geocache"
_cartridge.Version = ""
_cartridge.Company = ""
_cartridge.Author = "Hugh"
_cartridge.TargetDevice = "SmartPhone"
_cartridge.TargetDeviceVersion = "0"
_cartridge.BuilderVersion = "1"
_cartridge.StateId = "1"
_cartridge.CountryId = "2"
_cartridge.Description = [[A sandbox.]]
_cartridge.StartingLocationDescription = [[]]
_cartridge.Visible = true
_cartridge.Complete = false
_cartridge.UseLogging = false
_cartridge.CreateDate = "12/25/2020 04:02:56 AM"
_cartridge.PublishDate = "1/1/1970 01:00:00 AM"
_cartridge.UpdateDate = "12/25/2020 04:06:27 AM"
_cartridge.LastPlayedDate = "1/1/1970 01:00:00 AM"
_cartridge.StartingLocation = Wherigo.INVALID_ZONEPOINT

function f(_object)
    local _copy = {}

    return _copy
end

return _cartridge

 

But, the following do not.

 

require "Wherigo"

ZonePoint = Wherigo.ZonePoint
Distance = Wherigo.Distance
Player = Wherigo.Player

_cartridge = Wherigo.ZCartridge()

_cartridge.Id = "00000000000000000000000000001337"
-- SNIP
_cartridge.StartingLocation = Wherigo.INVALID_ZONEPOINT

function f(_object)
    local _copy = {}
    setmetatable(_copy, nil)

    return _copy
end

return _cartridge

 

require "Wherigo"

ZonePoint = Wherigo.ZonePoint
Distance = Wherigo.Distance
Player = Wherigo.Player

_cartridge = Wherigo.ZCartridge()

_cartridge.Id = "00000000000000000000000000001337"
-- SNIP
_cartridge.StartingLocation = Wherigo.INVALID_ZONEPOINT

function f(_object)
    local _copy = {}
    setmetatable(_copy, {})

    return _copy
end

return _cartridge

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Followers 0
×
×
  • Create New...