[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "table as parameter" problem (I AM A NEWBIE)
- From: "Robert G. Jakabosky" <bobby@...>
- Date: Mon, 9 Apr 2012 02:57:18 -0700
Change this:
f1.p(t)
to this:
f1:p(t)
The ':' syntax is for calling methods.
On Monday 09, 桑伟 wrote:
> Hi, all
> Sorry for this stupid question. I try to keep it simple. I have two files:
> -- file1 --------------
> module(..., package.seeall)
> function new()
> local t = {}
> function t:p(params)
> print(params.name)
> end
> return t
> end
> --- file2 -------------
> f1 = require("f1").new()
> local t = { name = "haha" }
> f1.p(t)
>
> When I run "*lua52 f2.lua*" at my macbook. I got these error messages:
> lua52: ./f1.lua:6: attempt to index local 'params' (a nil value)
> stack traceback:
> ./f1.lua:6: in function 'p'
> f2.lua:3: in main chunk
> [C]: in ?
>
> Anybody can help?
--
Robert G. Jakabosky