lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I am writing a small lua module and after some struggling I can only
manage to require it like:

  local canvas = require 'canvas'

But I can *not* require it like plain:

  require 'canvas'

The problem is, the module is a table *and* an 'instance' of a
'class'. So after 'require', user must access
a table *and* an instance. It can then use this instance to create
more 'brother' instances.
This behavior is defined here:

Here is part of the module code (just the show my problem):

local pairs, print, setmetatable, unpack, type, error, select = pairs,
print, setmetatable, unpack, type, error, select


-- Canvas declaration
local Canvas = {}
Canvas.__index = Canvas

Canvas.colorTable = {} = {0, 0, 255} = {255, 0, 0} = {0, 255, 0} = {0, 0, 0}
Canvas.colorTable.white = {255, 255, 255}

function Canvas.newcanvas(surface)
	local canvas = {}
	canvas.surface = surface
	setmetatable(canvas, Canvas)
	return canvas

function Canvas:new(...)
	local argType = type(...)
	local surface

        -- stuff

	return Canvas.newcanvas(surface)

function Canvas:flush()

-- Create base instance
return Canvas.newcanvas(otherModule:CreateSurface