From ffb686556f34d8ddfe5a3a8e00882ca08e33ea8b Mon Sep 17 00:00:00 2001 From: Enyby Date: Sat, 9 Mar 2019 23:00:28 +0200 Subject: [PATCH] Fix loadlib. --- src/core/org/luaj/vm2/lib/PackageLib.java | 62 +++++++++++------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/core/org/luaj/vm2/lib/PackageLib.java b/src/core/org/luaj/vm2/lib/PackageLib.java index 539d137d..db344818 100644 --- a/src/core/org/luaj/vm2/lib/PackageLib.java +++ b/src/core/org/luaj/vm2/lib/PackageLib.java @@ -30,9 +30,9 @@ import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; import org.luaj.vm2.Varargs; -/** - * Subclass of {@link LibFunction} which implements the lua standard package and module - * library functions. +/** + * Subclass of {@link LibFunction} which implements the lua standard package and module + * library functions. * *

Lua Environment Variables

* The following variables are available to lua scrips when this library has been loaded: @@ -50,14 +50,14 @@ import org.luaj.vm2.Varargs; * * *

Loading

- * Typically, this library is included as part of a call to either + * Typically, this library is included as part of a call to either * {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()} or {@link org.luaj.vm2.lib.jme.JmePlatform#standardGlobals()} *
 {@code
  * Globals globals = JsePlatform.standardGlobals();
  * System.out.println( globals.get("require").call"foo") );
  * } 
*

- * To instantiate and use it directly, + * To instantiate and use it directly, * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as: *

 {@code
  * Globals globals = new Globals();
@@ -67,8 +67,8 @@ import org.luaj.vm2.Varargs;
  * } 
*

Limitations

* This library has been implemented to match as closely as possible the behavior in the corresponding library in C. - * However, the default filesystem search semantics are different and delegated to the bas library - * as outlined in the {@link BaseLib} and {@link org.luaj.vm2.lib.jse.JseBaseLib} documentation. + * However, the default filesystem search semantics are different and delegated to the bas library + * as outlined in the {@link BaseLib} and {@link org.luaj.vm2.lib.jse.JseBaseLib} documentation. *

* @see LibFunction * @see BaseLib @@ -156,7 +156,7 @@ public class PackageLib extends TwoArgFunction { } - /** Set the lua path used by this library instance to a new value. + /** Set the lua path used by this library instance to a new value. * Merely sets the value of {@link path} to be used in subsequent searches. */ public void setLuaPath( String newLuaPath ) { package_.set(_PATH, LuaValue.valueOf(newLuaPath)); @@ -168,33 +168,33 @@ public class PackageLib extends TwoArgFunction { // ======================== Package loading ============================= - /** + /** * require (modname) * - * Loads the given module. The function starts by looking into the package.loaded table - * to determine whether modname is already loaded. If it is, then require returns the value + * Loads the given module. The function starts by looking into the package.loaded table + * to determine whether modname is already loaded. If it is, then require returns the value * stored at package.loaded[modname]. Otherwise, it tries to find a loader for the module. * - * To find a loader, require is guided by the package.searchers sequence. - * By changing this sequence, we can change how require looks for a module. + * To find a loader, require is guided by the package.searchers sequence. + * By changing this sequence, we can change how require looks for a module. * The following explanation is based on the default configuration for package.searchers. * - * First require queries package.preload[modname]. If it has a value, this value - * (which should be a function) is the loader. Otherwise require searches for a Lua loader using - * the path stored in package.path. If that also fails, it searches for a Java loader using + * First require queries package.preload[modname]. If it has a value, this value + * (which should be a function) is the loader. Otherwise require searches for a Lua loader using + * the path stored in package.path. If that also fails, it searches for a Java loader using * the classpath, using the public default constructor, and casting the instance to LuaFunction. * - * Once a loader is found, require calls the loader with two arguments: modname and an extra value + * Once a loader is found, require calls the loader with two arguments: modname and an extra value * dependent on how it got the loader. If the loader came from a file, this extra value is the file name. - * If the loader is a Java instance of LuaFunction, this extra value is the environment. - * If the loader returns any non-nil value, require assigns the returned value to package.loaded[modname]. - * If the loader does not return a non-nil value and has not assigned any value to package.loaded[modname], + * If the loader is a Java instance of LuaFunction, this extra value is the environment. + * If the loader returns any non-nil value, require assigns the returned value to package.loaded[modname]. + * If the loader does not return a non-nil value and has not assigned any value to package.loaded[modname], * then require assigns true to this entry. * In any case, require returns the final value of package.loaded[modname]. - * + * * If there is any error loading or running the module, or if it cannot find any loader for the module, * then require raises an error. - */ + */ public class require extends OneArgFunction { public LuaValue call( LuaValue arg ) { LuaString name = arg.checkstring(); @@ -213,7 +213,7 @@ public class PackageLib extends TwoArgFunction { for ( int i=1; true; i++ ) { LuaValue searcher = tbl.get(i); if ( searcher.isnil() ) { - error( "module '"+name+"' not found: "+name+sb ); + error( "module '"+name+"' not found: "+name+sb ); } /* call loader with module name as argument */ @@ -229,14 +229,14 @@ public class PackageLib extends TwoArgFunction { result = loader.arg1().call(name, loader.arg(2)); if ( ! result.isnil() ) loaded.set( name, result ); - else if ( (result = loaded.get(name)) == _SENTINEL ) + else if ( (result = loaded.get(name)) == _SENTINEL ) loaded.set( name, result = LuaValue.TRUE ); return result; } } public static class loadlib extends VarArgFunction { - public Varargs loadlib( Varargs args ) { + public Varargs invoke( Varargs args ) { args.checkstring(1); return varargsOf(NIL, valueOf("dynamic libraries not enabled"), valueOf("absent")); } @@ -246,7 +246,7 @@ public class PackageLib extends TwoArgFunction { public Varargs invoke(Varargs args) { LuaString name = args.checkstring(1); LuaValue val = package_.get(_PRELOAD).get(name); - return val.isnil()? + return val.isnil()? valueOf("\n\tno field package.preload['"+name+"']"): val; } @@ -258,7 +258,7 @@ public class PackageLib extends TwoArgFunction { // get package path LuaValue path = package_.get(_PATH); - if ( ! path.isstring() ) + if ( ! path.isstring() ) return valueOf("package.path is not a string"); // get the searchpath function. @@ -270,7 +270,7 @@ public class PackageLib extends TwoArgFunction { LuaString filename = v.arg1().strvalue(); // Try to load the file. - v = globals.loadfile(filename.tojstring()); + v = globals.loadfile(filename.tojstring()); if ( v.arg1().isfunction() ) return LuaValue.varargsOf(v.arg1(), filename); @@ -355,9 +355,9 @@ public class PackageLib extends TwoArgFunction { StringBuffer sb = new StringBuffer(j); for ( int i=0; i