Improve compatibility with C-based lua.
This commit is contained in:
@@ -86,6 +86,7 @@ public class LuaError extends RuntimeException {
|
||||
|
||||
/** Add file and line info to a message */
|
||||
private static String addFileLine( String message, int level ) {
|
||||
if ( message == null ) return message;
|
||||
LuaFunction f = LuaThread.getCallstackFunction(level);
|
||||
return f!=null? f+": "+message: message;
|
||||
}
|
||||
|
||||
@@ -37,22 +37,22 @@ public class PackageLib extends OneArgFunction {
|
||||
|
||||
public static String DEFAULT_LUA_PATH = "?.lua";
|
||||
|
||||
/** Most recent instance of PackageLib */
|
||||
public static PackageLib instance;
|
||||
|
||||
public InputStream STDIN = null;
|
||||
public PrintStream STDOUT = System.out;
|
||||
public LuaTable LOADED;
|
||||
public LuaTable PACKAGE;
|
||||
|
||||
/** Most recent instance of PackageLib */
|
||||
public static PackageLib instance;
|
||||
|
||||
/** Loader that loads from preload table if found there */
|
||||
public final LuaValue preload_loader;
|
||||
public LuaValue preload_loader;
|
||||
|
||||
/** Loader that loads as a lua script using the LUA_PATH */
|
||||
public final LuaValue lua_loader;
|
||||
public LuaValue lua_loader;
|
||||
|
||||
/** Loader that loads as a Java class. Class must have public constructor and be a LuaValue */
|
||||
public final LuaValue java_loader;
|
||||
public LuaValue java_loader;
|
||||
|
||||
private static final LuaString _M = valueOf("_M");
|
||||
private static final LuaString _NAME = valueOf("_NAME");
|
||||
@@ -76,9 +76,6 @@ public class PackageLib extends OneArgFunction {
|
||||
|
||||
public PackageLib() {
|
||||
instance = this;
|
||||
preload_loader = new PkgLibV(env,"preload_loader", OP_PRELOAD_LOADER,this);
|
||||
lua_loader = new PkgLibV(env,"lua_loader", OP_LUA_LOADER,this);
|
||||
java_loader = new PkgLibV(env,"java_loader", OP_JAVA_LOADER,this);
|
||||
}
|
||||
|
||||
public LuaValue call(LuaValue arg) {
|
||||
@@ -91,9 +88,9 @@ public class PackageLib extends OneArgFunction {
|
||||
_LOADLIB, new PkgLibV(env,"loadlib",OP_LOADLIB,this),
|
||||
_SEEALL, new PkgLib1(env,"seeall",OP_SEEALL,this),
|
||||
_LOADERS, listOf(new LuaValue[] {
|
||||
preload_loader,
|
||||
lua_loader,
|
||||
java_loader,
|
||||
preload_loader = new PkgLibV(env,"preload_loader", OP_PRELOAD_LOADER,this),
|
||||
lua_loader = new PkgLibV(env,"lua_loader", OP_LUA_LOADER,this),
|
||||
java_loader = new PkgLibV(env,"java_loader", OP_JAVA_LOADER,this),
|
||||
}) }) );
|
||||
return env;
|
||||
}
|
||||
|
||||
@@ -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