level 3
chaosink
楼主
local M = {}
local function new(r, i) return {r = r, i = i} end
local function tostring(c)
return "(" .. c.r .. "," .. c.i .. ")"
end
return {
new= new,
tostring= tostring,
}
以上是complex.lua的内容,是一个简单的复数module。
local cpx = require "complex"
a = cpx.new(1, 2)
print(cpx.tostring(a))
以上是test.lua的内容,用来测试复数module。
我的问题是:为什么在去掉tostring()之前的local后,会报错说c的i域为nil?
2015年09月23日 05点09分
1
local function new(r, i) return {r = r, i = i} end
local function tostring(c)
return "(" .. c.r .. "," .. c.i .. ")"
end
return {
new= new,
tostring= tostring,
}
以上是complex.lua的内容,是一个简单的复数module。
local cpx = require "complex"
a = cpx.new(1, 2)
print(cpx.tostring(a))
以上是test.lua的内容,用来测试复数module。
我的问题是:为什么在去掉tostring()之前的local后,会报错说c的i域为nil?