Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fields and methods of metatable are not visible on table right after setmetatable

This is Pico-8 lua. I have the following function, which fails at the marked assert. I do not understand how this can happen. I have used setmetatable on two other occasions and it is working there. I have no clue here.

function particle:new(o)
    setmetatable(o, self)
    assert(self.spd, "works")
    assert(getmetatable(o).spd, "works")
    assert(o.spd, "this fails") -- < this assert fails, the ones above succeed
    add(anims,o)
end

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Looks like you forgot

self.__index = self

Without this o.spd will not refer to particle.spd, if o.spd is nil.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading