how does bootstrap.register_metatable work?

Place to get help with not working mods / modding interface.
Post Reply
credomane
Filter Inserter
Filter Inserter
Posts: 278
Joined: Tue Apr 12, 2016 6:21 pm
Contact:

how does bootstrap.register_metatable work?

Post 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.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: how does bootstrap.register_metatable work?

Post 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)

Post Reply

Return to “Modding help”