Page 1 of 1

how does bootstrap.register_metatable work?

Posted: Fri Oct 07, 2022 1:49 am
by credomane
I'm probably being dense but how exactly do I use this function and how does it work?

This is a terrible snippet as the npc class does a lot more than this...with the help of several other files. I've really come to dislike the one event handler per event per mod. It is making my life difficult or it another case of me being dense again...LUA is *really* not my forte. :/

Code: Select all

function npc:new(o)
    o = o or {}
    setmetatable(o, self)
    self.__index = self
    return o
end
How do I go about using register_metatable in this case? `register_metatable('npc',npc)`? Do I need to call it with a unique name for however many NPC I have in existence? Do I call it inside the npc:new function or elsewhere?

Lua not having dedicated class keyword (even as syntax sugar like javascript does) makes this a pain sometimes.

Re: how does bootstrap.register_metatable work?

Posted: Fri Oct 07, 2022 4:39 am
by DaveMcW
Here is a quick metatable tutorial: https://www.lua.org/pil/13.1.html

After following the tutorial, you would do:

Code: Select all

script.register_metatable("Set", Set.mt)