Hey, I’m having trouble trouble emulating OOP in Lua and creating inheritance
Derived class:
local evolvable = require("Objects.evolvable"); local player = {}; player.\_\_index = player; function player.new() local self = setmetatable(evolvable.new(), {\_\_index = evolvable}) return self end function player:stepNow() print("PLAYER STEP"); end return player;
Base class:
local evolvable = {}; evolvable.\_\_index = evolvable; function evolvable.new() local self = setmetatable({}, evolvable) end function evolvable:stepNow() print("FALLBACK"); end return evolvable;
I want it to print “PLAYER STEP” when I call the code below, but it falls back to the base class and prints “FALLBACK”.
local temp = player.new(); temp:stepNow();
I’m having trouble following the convoluted logic here. Any tips?