Improve compatibility with C-based lua.
This commit is contained in:
@@ -36,5 +36,5 @@ print( 'os.remove(q)', pcall( os.remove, q ) )
|
||||
-- print( 'os.setlocale("jp")', pcall( os.setlocale, "jp" ) )
|
||||
-- print( 'os.setlocale("us","monetary")', pcall( os.setlocale, "us", "monetary" ) )
|
||||
-- print( 'os.setlocale(nil,"all")', pcall( os.setlocale, nil, "all" ) )
|
||||
print( 'os.setlocale("c")', pcall( os.setlocale, "c" ) )
|
||||
print( 'os.setlocale("C")', pcall( os.setlocale, "C" ) )
|
||||
print( 'os.exit', type(os.exit) )
|
||||
|
||||
@@ -108,15 +108,26 @@ print(string.format("(%08x) (%08d) (%08o)", 255, 255, 255))
|
||||
|
||||
print(string.format("simple%ssimple", " simple "))
|
||||
|
||||
print(string.format("%%"))
|
||||
local testformat = function(message,fmt,...)
|
||||
local s,e = pcall( string.format, fmt, ... )
|
||||
if s then
|
||||
print( message, string.byte(e,1,#e) )
|
||||
else
|
||||
print( message, 'error', e )
|
||||
end
|
||||
end
|
||||
|
||||
specials = "\"specials\": %% \000 \r \n"
|
||||
print(string.format("specials (%%s): ----->%s<----", specials) )
|
||||
print(string.format("specials (%%q): ----->%q<----", specials) )
|
||||
print(string.format("controls (%%q): ----->%q<----", ' \a \b \f \t \v \\ ') )
|
||||
print(string.format("extended (%%q): ----->%q<----", ' \222 \223 \224 ') )
|
||||
print(string.format("embedded newlines: %s\n%s\n%s", '======>', '<======>', '<======='))
|
||||
print(string.format("this is a %s long string", string.rep("really, ", 30)))
|
||||
|
||||
testformat('plain %', "%%")
|
||||
testformat("specials (%s)", "---%s---", specials)
|
||||
testformat("specials (%q)", "---%q---", specials)
|
||||
testformat("controls (%q)", "---%q---", ' \a \b \f \t \v \\ ')
|
||||
testformat("extended (%q)", "---%q---", ' \222 \223 \224 ')
|
||||
testformat("embedded newlines", "%s\r%s\n%s", '===', '===', '===')
|
||||
|
||||
-- format long string
|
||||
print("this is a %s long string", string.rep("really, ", 30))
|
||||
|
||||
local function pc(...)
|
||||
local s,e = pcall(...)
|
||||
return s and e or 'false-'..type(e)
|
||||
|
||||
@@ -124,10 +124,20 @@ local function fib_good(n)
|
||||
return helper(1, 1, 1)
|
||||
end
|
||||
|
||||
print(pcall(fib_bad, 30))
|
||||
print(pcall(fib_bad, 25000))
|
||||
print(pcall(fib_good, 30))
|
||||
print(pcall(fib_good, 25000))
|
||||
local aliases = {
|
||||
['1.#INF'] = 'inf',
|
||||
['-1.#INF'] = '-inf',
|
||||
['1.#IND'] = 'nan',
|
||||
['-1.#IND'] = 'nan',
|
||||
}
|
||||
|
||||
local p = function( s,e )
|
||||
print( s, e and aliases[tostring(e)] or e )
|
||||
end
|
||||
p(pcall(fib_bad, 30))
|
||||
p((pcall(fib_bad, 25000)))
|
||||
p(pcall(fib_good, 30))
|
||||
p(pcall(fib_good, 25000))
|
||||
|
||||
local function fib_all(n, i, a, b)
|
||||
i = i or 1
|
||||
|
||||
Reference in New Issue
Block a user