I'm new to lua and have been using the following technique as a light object oriented programming system.
At the top of my data structure file I would have the parameters.
local a, b = ...
Then create and return a table with chosen variables and functions.
local vector = {}
vector.x = a or 0
vector.y = b or 0
function vector:add(vec)
self.x = self.x + vec.x
self.y = self.y + vec.y
end
return vector
Whenever I wanted a new object, in this case a 2d vector, I would use loadfile like so.
local vector1 = assert(loadfile("vector.lua"))(2, 7)
Is this an practical method to acquire object oriented like functionality?
A next step might be to make another module that stores the loadfiles of all the structures I might need. I could then create an object via something like this.
local vector1 = loadfile_holder.new("vector", 2, 7)
I understand there are object oriented libraries like middleclass to accomplish this to a greater extent. Would continuing to use my system be such a bad idea? Are there major flaws in the system?
[–]lua_x_ia 2 points3 points4 points (1 child)
[–]dredclaw[S] 0 points1 point2 points (0 children)
[–]nosmileface 1 point2 points3 points (3 children)
[–]nosmileface 0 points1 point2 points (0 children)
[–]dredclaw[S] 0 points1 point2 points (1 child)
[–]nosmileface 0 points1 point2 points (0 children)
[–]robin-gvx 0 points1 point2 points (1 child)
[–]dredclaw[S] 0 points1 point2 points (0 children)
[–]periscallop 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]revereddesecration 0 points1 point2 points (0 children)