Improved argument handling.

This commit is contained in:
James Roseborough
2008-07-22 19:17:50 +00:00
parent eae183e334
commit 89c38d00cc
6 changed files with 18 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ public class CoroutineLib extends LFunction {
for ( int i=1; i<=YIELD; i++ ) for ( int i=1; i<=YIELD; i++ )
lib.put(NAMES[i], new CoroutineLib(i)); lib.put(NAMES[i], new CoroutineLib(i));
globals.put("coroutine",lib); globals.put("coroutine",lib);
PackageLib.setIsLoaded("coroutine", lib);
} }
private final int id; private final int id;

View File

@@ -120,7 +120,9 @@ public class MathLib extends LFunction {
math.put( "huge", new LDouble( Double.MAX_VALUE ) ); math.put( "huge", new LDouble( Double.MAX_VALUE ) );
math.put( "pi", new LDouble( Math.PI ) ); math.put( "pi", new LDouble( Math.PI ) );
globals.put( "math", math ); globals.put( "math", math );
PackageLib.setIsLoaded("math", math);
platform = Platform.getInstance(); platform = Platform.getInstance();
} }
private static Random random = null; private static Random random = null;

View File

@@ -95,6 +95,12 @@ public class PackageLib extends LFunction {
pckg.put( "loaders", loaders ); pckg.put( "loaders", loaders );
pckg.put( _PATH, _LUA_PATH ); pckg.put( _PATH, _LUA_PATH );
globals.put( "package", pckg ); 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 ) { public static void setLuaPath( String newLuaPath ) {
@@ -180,7 +186,7 @@ public class PackageLib extends LFunction {
int n = vm.gettop(); int n = vm.gettop();
LValue value = LOADED.get(modname); LValue value = LOADED.get(modname);
LTable module; 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) */ /* try global variable (and create one if it does not exist) */
module = findtable( vm._G, modname ); module = findtable( vm._G, modname );
@@ -322,7 +328,11 @@ public class PackageLib extends LFunction {
} }
public static void loadlib( LuaState vm ) { 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");
} }

View File

@@ -71,6 +71,7 @@ public class StringLib extends LFunction {
for ( int i=1; i<NAMES.length; i++ ) for ( int i=1; i<NAMES.length; i++ )
string.put(NAMES[i], new StringLib(i)); string.put(NAMES[i], new StringLib(i));
globals.put( "string", string ); globals.put( "string", string );
PackageLib.setIsLoaded("string", string);
} }
private final int id; private final int id;

View File

@@ -60,6 +60,7 @@ public class TableLib extends LFunction {
for ( int i=1; i<NAMES.length; i++ ) for ( int i=1; i<NAMES.length; i++ )
table.put( NAMES[i], new TableLib(i) ); table.put( NAMES[i], new TableLib(i) );
globals.put( "table", table ); globals.put( "table", table );
PackageLib.setIsLoaded("table", table);
} }
private final int id; private final int id;

View File

@@ -141,10 +141,10 @@ public class LuaState extends Lua {
* BaseLib, CoroutineLib, MathLib, PackageLib, TableLib, StringLib * BaseLib, CoroutineLib, MathLib, PackageLib, TableLib, StringLib
*/ */
public void installStandardLibs() { public void installStandardLibs() {
PackageLib.install(_G);
BaseLib.install(_G); BaseLib.install(_G);
CoroutineLib.install(_G); CoroutineLib.install(_G);
MathLib.install(_G); MathLib.install(_G);
PackageLib.install(_G);
TableLib.install(_G); TableLib.install(_G);
StringLib.install(_G); StringLib.install(_G);
} }