- 论坛徽章:
- 5
|
显然短路。字节码是这样的:- luac -l -l -- "noname\2012-11-05-1.lua"
- main <noname\2012-11-05-1.lua:0,0> (15 instructions at 006C7CF8)
- 0+ params, 2 slots, 1 upvalue, 1 local, 3 constants, 0 functions
- 1 [1] GETTABUP 0 0 -1 ; _ENV "a"
- 2 [1] LT 0 -2 0 ; 0 -
- 3 [1] JMP 0 3 ; to 7
- 4 [1] GETTABUP 0 0 -3 ; _ENV "b"
- 5 [1] LT 1 -2 0 ; 0 -
- 6 [1] JMP 0 7 ; to 14
- 7 [1] GETTABUP 0 0 -1 ; _ENV "a"
- 8 [1] EQ 0 0 -2 ; - 0
- 9 [1] JMP 0 3 ; to 13
- 10 [1] GETTABUP 0 0 -3 ; _ENV "b"
- 11 [1] LT 1 0 -2 ; - 0
- 12 [1] JMP 0 1 ; to 14
- 13 [1] LOADBOOL 0 0 1
- 14 [1] LOADBOOL 0 1 0
- 15 [1] RETURN 0 1
复制代码 所以明显这个描述错误了。
另外,manual里面是这么描述的:
The negation operator not always returns false or true. The conjunction operator and returns its first argument if this value is false or nil; otherwise, and returns its second argument. The disjunction operator or returns its first argument if this value is different from nil and false; otherwise, or returns its second argument. Both and and or use short-cut evaluation; that is, the second operand is evaluated only if necessary. |
|