Improved argument handling.
This commit is contained in:
@@ -54,6 +54,7 @@ public class CoroutineLib extends LFunction {
|
||||
for ( int i=1; i<=YIELD; i++ )
|
||||
lib.put(NAMES[i], new CoroutineLib(i));
|
||||
globals.put("coroutine",lib);
|
||||
PackageLib.setIsLoaded("coroutine", lib);
|
||||
}
|
||||
|
||||
private final int id;
|
||||
|
||||
@@ -120,7 +120,9 @@ public class MathLib extends LFunction {
|
||||
math.put( "huge", new LDouble( Double.MAX_VALUE ) );
|
||||
math.put( "pi", new LDouble( Math.PI ) );
|
||||
globals.put( "math", math );
|
||||
PackageLib.setIsLoaded("math", math);
|
||||
platform = Platform.getInstance();
|
||||
|
||||
}
|
||||
|
||||
private static Random random = null;
|
||||
|
||||
@@ -95,6 +95,12 @@ public class PackageLib extends LFunction {
|
||||
pckg.put( "loaders", loaders );
|
||||
pckg.put( _PATH, _LUA_PATH );
|
||||
globals.put( "package", pckg );
|
||||
setIsLoaded( "package", pckg );
|
||||
}
|
||||
|
||||
/** Allow packages to mark themselves as loaded */
|
||||
public static void setIsLoaded(String name, LTable value) {
|
||||
LOADED.put(name, value);
|
||||
}
|
||||
|
||||
public static void setLuaPath( String newLuaPath ) {
|
||||
@@ -180,7 +186,7 @@ public class PackageLib extends LFunction {
|
||||
int n = vm.gettop();
|
||||
LValue value = LOADED.get(modname);
|
||||
LTable module;
|
||||
if ( value.luaGetType() != Lua.LUA_TTABLE ) { /* not found? */
|
||||
if ( ! value.isTable() ) { /* not found? */
|
||||
|
||||
/* try global variable (and create one if it does not exist) */
|
||||
module = findtable( vm._G, modname );
|
||||
@@ -322,7 +328,11 @@ public class PackageLib extends LFunction {
|
||||
}
|
||||
|
||||
public static void loadlib( LuaState vm ) {
|
||||
vm.error( "loadlib not implemented" );
|
||||
vm.checkstring(2);
|
||||
vm.resettop();
|
||||
vm.pushnil();
|
||||
vm.pushstring("dynamic libraries not enabled");
|
||||
vm.pushstring("absent");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ public class StringLib extends LFunction {
|
||||
for ( int i=1; i<NAMES.length; i++ )
|
||||
string.put(NAMES[i], new StringLib(i));
|
||||
globals.put( "string", string );
|
||||
PackageLib.setIsLoaded("string", string);
|
||||
}
|
||||
|
||||
private final int id;
|
||||
|
||||
@@ -60,6 +60,7 @@ public class TableLib extends LFunction {
|
||||
for ( int i=1; i<NAMES.length; i++ )
|
||||
table.put( NAMES[i], new TableLib(i) );
|
||||
globals.put( "table", table );
|
||||
PackageLib.setIsLoaded("table", table);
|
||||
}
|
||||
|
||||
private final int id;
|
||||
|
||||
@@ -141,10 +141,10 @@ public class LuaState extends Lua {
|
||||
* BaseLib, CoroutineLib, MathLib, PackageLib, TableLib, StringLib
|
||||
*/
|
||||
public void installStandardLibs() {
|
||||
PackageLib.install(_G);
|
||||
BaseLib.install(_G);
|
||||
CoroutineLib.install(_G);
|
||||
MathLib.install(_G);
|
||||
PackageLib.install(_G);
|
||||
TableLib.install(_G);
|
||||
StringLib.install(_G);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user