lua的函数的环境和变量
来源:互联网 发布:网络监控安装步骤图解 编辑:程序博客网 时间:2024/05/01 08:46
--[[
Returns the current environment in use by the function. f can be a Lua function or a number that specifies the function at that stack level: Level 1 is the function calling getfenv.
If the given function is not a Lua function, or if f is 0, getfenv returns the global environment. The default for f is 1.
]]
f = 4
function a()
f = "a"
print( getfenv(b).f, getfenv(0).f, getfenv(1).f, getfenv(2).f, getfenv(3).f)
end
A = {}
setmetatable(A, {__index = _G})
setfenv(a, A)
--print(getfenv(a).f)
function b()
f = "b"
A.a()
end
B = {}
setmetatable(B, {__index = _G})
setfenv(b, B)
function c()
f = "c"
B.b()
end
C = {}
setmetatable(C, {__index = _G})
setfenv(c, C)
c()
print(f, A.f, B.f, C.f )
Returns the current environment in use by the function. f can be a Lua function or a number that specifies the function at that stack level: Level 1 is the function calling getfenv.
If the given function is not a Lua function, or if f is 0, getfenv returns the global environment. The default for f is 1.
]]
f = 4
function a()
f = "a"
print( getfenv(b).f, getfenv(0).f, getfenv(1).f, getfenv(2).f, getfenv(3).f)
end
A = {}
setmetatable(A, {__index = _G})
setfenv(a, A)
--print(getfenv(a).f)
function b()
f = "b"
A.a()
end
B = {}
setmetatable(B, {__index = _G})
setfenv(b, B)
function c()
f = "c"
B.b()
end
C = {}
setmetatable(C, {__index = _G})
setfenv(c, C)
c()
print(f, A.f, B.f, C.f )
- lua的函数的环境和变量
- php和lua的变量作用域
- lua函数.和:的使用
- Lua 语言的常见的相关base 变量和base函数
- C/C++调用lua的table,table包含函数,table和变量
- Lua的局部变量
- Lua的局部变量
- cocos2d tolua C++对象使用lua对象的变量,函数
- 【Lua】【2】Lua基本的函数和控制结构
- Lua环境的搭建
- Lua.1 lua的类型与变量
- Lua和C的交互说明(函数)
- Lua之变量环境
- kotlin的变量和函数
- lua学习(2)_____lua的注释和全局变量、局部变量
- lua 中table的字符串索引和变量索引
- Lua调用C++的变量
- lua 交换变量的值
- Android NDK中重新编译已有so库!
- Flex BusyIndicator
- 使用cPickle来序列化、持久化 python对象
- .Net Framework4.0安装错误解决方案
- ultraedit 正则表达式 -删除包含某个字符串的所有行 .
- lua的函数的环境和变量
- have a look!
- 《干货集锦》——前端大牛 Addy Osmani 的15个精彩PPT
- Linux平台代码覆盖率测试工具gcov简介
- 点滴记录--递归
- 调整导航条上leftBarButtonItem和rightBarButtonItem与屏幕边界的间距
- 15个HTML5的初级技巧
- addslashes与mysql_real_escape_string的区别
- 程序员学习能力提升三要素