[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: NCLua canvas module implementation: Silly question
- From: Duncan Cross <duncan.cross@...>
- Date: Sun, 8 Jan 2012 19:29:56 +0000
2012/1/8 Ezequiel García <elezegarcia@gmail.com>:
> Hi,
> 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:
>
> http://www.lua.inf.puc-rio.br/~francisco/nclua/referencia/canvas.html
>
> Here is part of the module code (just the show my problem):
Try first removing the module('canvas') line (module() is not useful
in situations like this, where you are constructing your own object
and returning it at the end), and then setting the global variable
yourself at the end, e.g.:
-- Create base instance
local baseInstance = Canvas.newcanvas(otherModule:CreateSurface
{caps='DSCAPS_PRIMARY|DSCAPS_FLIPPING'})
_G.canvas = baseInstance
return baseInstance
-Duncan