Lua local function与function区别
来源:互联网 发布:js隐藏span 编辑:程序博客网 时间:2024/06/14 04:34
1 使用function声明的函数为全局函数,在被引用时可以不会因为声明的顺序而找不到
2 使用local function声明的函数为局部函数,在引用的时候必须要在声明的函数后面
例子:
下面这段代码会报函数找不到的错误:lua: test.lua:3: attempt to call global ‘test1’ (a nil value)
function test() test2() test1()endlocal function test1() print("hello test1")endfunction test2() print("hello test2")endtest()
改为一下两种方式就可以正常运行
1 local function的声明放在引用的前面
local function test1() print("hello test1")endfunction test() test2() test1()endfunction test2() print("hello test2")endtest()
2 local function声明使用function方式
function test() test2() test1()endfunction test1() print("hello test1")endfunction test2() print("hello test2")endtest()
0 0
- Lua local function与function区别
- Lua local function与function区别
- function 与 new function 区别
- (function ( ){...})( ) 与 (function ( ){...}( )) 有区别
- lua function
- Lua function
- lua-function
- lua function
- Function 与 Functor 区别
- Function 与 new Function 的区别
- jQuery(function(){})与(function(){})(jQuery)的区别
- jQuery(function(){ }) 与 (function(){ })(jQuery); 区别
- jQuery(function(){ }) 与 (function(){ })(jQuery); 区别
- jQuery(function(){})与(function(){})(jQuery)的区别
- jQuery(function(){})与(function(){})(jQuery)的区别
- jQuery(function(){})与(function(){})(jQuery)的区别
- jQuery(function(){})与(function(){})(jQuery)的区别
- jQuery(function(){})与(function(){})(jQuery)区别
- Notepad++连接QQ浏览器
- 如何连接开发环境和生产环境?
- Mysql之事务与视图
- Android Logcat 直接输出JSON格式的数据
- NKOI半期 3665 摘橘子
- Lua local function与function区别
- nav元素
- mybatis
- 怎么在ZBrush中渲染漫画风格的插画
- SwipeRefreshLayout与viewpager的滑动冲突的解决
- block、inline和inline-block概念和区别
- 递推求阶乘
- maven管理本地jar包
- lightoj 1016 - Brush (II) 【贪心】