Issues with Metatables and Logging
Posted: Thu Sep 05, 2013 10:13 pm
Hello, I'm currently working on a project where I have a file Unit.lua containing a global table tUnit with tUnit.__index = tUnit set. tUnit is used to create table instances of units through passing a table through tUnit:new{args}. For some reason, using
it says t is a nil value.
I've extensively read about metatables and this is baffling in how irritating this is. tUnit has various functions defined and throughout tUnit:new(t) I use the self operator to initialize values. No matter what I do, t is continuously nil, and the meta table breaks. Any ideas? What am I doing wrong here?
Secondly, I am trying to set up a logging system and need to know how I can reopen a log that is already created and write to it. Do I just use love.filesystem.newFile with the same name? It works for the first line, but I don't know anything else because the tUnit class is breaking.
Code: Select all
function tUnit:new(t)
setmetatable(t, self)
I've extensively read about metatables and this is baffling in how irritating this is. tUnit has various functions defined and throughout tUnit:new(t) I use the self operator to initialize values. No matter what I do, t is continuously nil, and the meta table breaks. Any ideas? What am I doing wrong here?
Secondly, I am trying to set up a logging system and need to know how I can reopen a log that is already created and write to it. Do I just use love.filesystem.newFile with the same name? It works for the first line, but I don't know anything else because the tUnit class is breaking.