首页  

lua local function 与 function 区别     所属分类 lua 浏览量 1174
local function 局部函数,必需声明之后再引用

function 全局函数 , 对 声明 和 引用 顺序无要求

test.lua

function test()
    test2()
    test1()
end
 
local function test1()
    print("hello test1")
end
 
function test2()
    print("hello test2")
end
 
test()



运行
lua test.lua


hello test2
lua: test.lua:3: attempt to call a nil value (global 'test1')
stack traceback:
	test.lua:3: in function 'test'
	test.lua:14: in main chunk
	[C]: in ?
	
两个修改方式
local function test1  先声明 后引用
local function test1  改为 function test1

上一篇     下一篇
prometheus VS influxdb

go语言历程

go语言特性及优点

aerospike udf 使用之 record

aerospike udf 使用之 list

aerospike udf 使用之 map