lua-users home
lua-l archive

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


On Thu, Oct 2, 2008 at 3:10 PM, Tim Channon <tc@gpsl.net> wrote:
> Where does argument 3 go?
>
>
> tagclass = {}
> tagmetatable = {__index = tagclass}
> function tagclass.new (kind, args, body)
>  local self = {}
>        self.kind=kind
>        self.args=args
>        self.body=body
>  setmetatable(self,tagmetatable)
>  return self
> end
>
> function tagclass:show()
>        print("kind",self.kind)
>        print("args",self.args)
>        print("body",self.body)
> end
>
> xx=tagclass:new("kindp", "argp", "bodyp")

This is syntactic sugar for

xx=tagclass.new(tagclass, "kindp", "argp", "bodyp")

You have to call your new() like a regular function:

xx=tagclass.new("kindp", "argp", "bodyp")

> xx:show()
>
> kind    table: 00887f48
> args    kindp
> body    argp

-- 
Dirk