Page 1 of 1

return table problem

Posted: Tue Sep 01, 2009 8:32 pm
by willthewarlock
I'm making a GUI library and I get error LFrame is nil value. Frame is a table in a other file(which is included in the GUI library)

Main Program:

Code: Select all

require('GUI.lua')

function load()
	local var = love.graphics.newImage('test.gif')
	LFrame = GUI:Create('Frame')
	LFrame:SetPos(10,10)
	LFrame:SetSize(100,100)
	LFrame:SetTitle('TEST')
	LFrame:SetBackgroundPic(var)
	LFrame:Show(true)
end 
GuiLibrary:

Code: Select all

GUI = { 
	Create = function(obj)
		if obj == 'Frame' or obj == 'Window' then
			c = {}
			for k, v in pairs(Frame) do
				c[k] = Frame[k]
			end
		end
		Objects[#Objects + 1] =  c
		return c
	end,
        -- more code
}

Re: return table problem

Posted: Tue Sep 01, 2009 8:36 pm
by bartbes
That's easy, you use GUI:Create, this means that the function GUI.Create should have the following prototype:
function (self, obj)

Because this isn't the case, obj is set as self, instead of the argument provided, so, obj == GUI, this means that the check fails, c is never set and there is a nil value returned.

Re: return table problem

Posted: Tue Sep 01, 2009 8:37 pm
by willthewarlock
Thanks