Variable attributes can prefix name list
In this format, the attribute applies to all names in the list; e.g. "global<const> print, require, math".
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
-- $Id: testes/all.lua $
|
||||
-- See Copyright Notice in file lua.h
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
global _soft, _port, _nomsg
|
||||
global T
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- $Id: testes/calls.lua $
|
||||
-- See Copyright Notice in file lua.h
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
print("testing functions and calls")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- $Id: testes/closure.lua $
|
||||
-- See Copyright Notice in file lua.h
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
print "testing closures"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- $Id: testes/code.lua $
|
||||
-- See Copyright Notice in file lua.h
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
if T==nil then
|
||||
(Message or print)('\n >>> testC not active: skipping opcode tests <<<\n')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- $Id: testes/files.lua $
|
||||
-- See Copyright Notice in file lua.h
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
local debug = require "debug"
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
-- $Id: testes/goto.lua $
|
||||
-- See Copyright Notice in file lua.h
|
||||
|
||||
global require
|
||||
global print, load, assert, string, setmetatable
|
||||
global collectgarbage, error
|
||||
global<const> require
|
||||
global<const> print, load, assert, string, setmetatable
|
||||
global<const> collectgarbage, error
|
||||
|
||||
print("testing goto and global declarations")
|
||||
|
||||
@@ -304,7 +304,7 @@ do
|
||||
|
||||
-- global variables cannot be to-be-closed
|
||||
checkerr("global X<close>", "cannot be")
|
||||
checkerr("global * <close>", "cannot be")
|
||||
checkerr("global <close> *", "cannot be")
|
||||
|
||||
do
|
||||
local X = 10
|
||||
@@ -345,7 +345,7 @@ do
|
||||
end
|
||||
|
||||
checkerr([[
|
||||
global foo <const>;
|
||||
global<const> foo;
|
||||
function foo (x) return end -- ERROR: foo is read-only
|
||||
]], "assign to const variable 'foo'")
|
||||
|
||||
@@ -357,7 +357,7 @@ do
|
||||
]], "%:2%:") -- correct line in error message
|
||||
|
||||
checkerr([[
|
||||
global * <const>;
|
||||
global<const> *;
|
||||
print(X) -- Ok to use
|
||||
Y = 1 -- ERROR
|
||||
]], "assign to const variable 'Y'")
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
print('testing scanner')
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
local debug = require "debug"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- $Id: testes/locals.lua $
|
||||
-- See Copyright Notice in file lua.h
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
print('testing local variables and environments')
|
||||
|
||||
@@ -181,23 +181,25 @@ assert(x==20)
|
||||
A = nil
|
||||
|
||||
|
||||
do -- constants
|
||||
do print("testing local constants")
|
||||
global assert<const>, load, string, X
|
||||
X = 1 -- not a constant
|
||||
local a<const>, b, c<const> = 10, 20, 30
|
||||
b = a + c + b -- 'b' is not constant
|
||||
assert(a == 10 and b == 60 and c == 30)
|
||||
|
||||
local function checkro (name, code)
|
||||
local st, msg = load(code)
|
||||
local gab = string.format("attempt to assign to const variable '%s'", name)
|
||||
assert(not st and string.find(msg, gab))
|
||||
end
|
||||
|
||||
checkro("y", "local x, y <const>, z = 10, 20, 30; x = 11; y = 12")
|
||||
checkro("x", "local x <const>, y, z <const> = 10, 20, 30; x = 11")
|
||||
checkro("z", "local x <const>, y, z <const> = 10, 20, 30; y = 10; z = 11")
|
||||
checkro("foo", "local foo <const> = 10; function foo() end")
|
||||
checkro("foo", "local foo <const> = {}; function foo() end")
|
||||
checkro("foo", "global foo <const>; function foo() end")
|
||||
checkro("foo", "local<const> foo = 10; function foo() end")
|
||||
checkro("foo", "local<const> foo <const> = {}; function foo() end")
|
||||
checkro("foo", "global<const> foo <const>; function foo() end")
|
||||
checkro("XX", "global XX <const>; XX = 10")
|
||||
checkro("XX", "local _ENV; global XX <const>; XX = 10")
|
||||
|
||||
@@ -218,8 +220,18 @@ do -- constants
|
||||
end
|
||||
|
||||
|
||||
|
||||
print"testing to-be-closed variables"
|
||||
|
||||
|
||||
do
|
||||
local st, msg = load("local <close> a, b")
|
||||
assert(not st and string.find(msg, "multiple"))
|
||||
|
||||
local st, msg = load("local a<close>, b<close>")
|
||||
assert(not st and string.find(msg, "multiple"))
|
||||
end
|
||||
|
||||
local function stack(n) n = ((n == 0) or stack(n - 1)) end
|
||||
|
||||
local function func2close (f, x, y)
|
||||
|
||||
@@ -8,11 +8,10 @@ local string = require "string"
|
||||
|
||||
global none
|
||||
|
||||
global print, assert, pcall, type, pairs, load
|
||||
global tonumber, tostring, select
|
||||
global<const> print, assert, pcall, type, pairs, load
|
||||
global<const> tonumber, tostring, select
|
||||
|
||||
local minint <const> = math.mininteger
|
||||
local maxint <const> = math.maxinteger
|
||||
local<const> minint, maxint = math.mininteger, math.maxinteger
|
||||
|
||||
local intbits <const> = math.floor(math.log(maxint, 2) + 0.5) + 1
|
||||
assert((1 << intbits) == 0)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- $Id: testes/nextvar.lua $
|
||||
-- See Copyright Notice in file lua.h
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
print('testing tables, next, and for')
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
print('testing pattern matching')
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
local function checkerror (msg, f, ...)
|
||||
local s, err = pcall(f, ...)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
-- ISO Latin encoding
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
print('testing strings and string library')
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
-- UTF-8 file
|
||||
|
||||
global * <const>
|
||||
global <const> *
|
||||
|
||||
print "testing UTF-8 library"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user