I keep getting an “attempt to index global ‘Foo’ (a nil value)” error.
Say I want to create a class using a module named ‘Foo’. To create an instance of the Foo class, I want to call Foo:new() from main.lua. I know I have to work with metatables and all that, but the error appears to precede that stuff.
If foo.lua is basically
module(...,package.seeall)
Foo = {}
Foo\_mt = {\_\_index = Foo}
function Foo:new(params)
local self = {}
setmetatable(self, Foo\_mt)
...
return self
end
then in main.lua, shouldn’t I be able to just write
require ("foo") --foo.lua is the doc
newFoo = Foo:new()
? [import]uid: 41305 topic_id: 9061 reply_id: 309061[/import]