Remove libs dependency from PackageLib.

This commit is contained in:
Enyby
2019-01-13 19:23:44 +02:00
parent 6f5af581e8
commit 9688d3c5fc
9 changed files with 326 additions and 326 deletions

View File

@@ -71,7 +71,7 @@ public class Bit32Lib extends TwoArgFunction {
"arshift", "lrotate", "lshift", "rrotate", "rshift" "arshift", "lrotate", "lshift", "rrotate", "rshift"
}); });
env.set("bit32", t); env.set("bit32", t);
env.get("package").get("loaded").set("bit32", t); if (!env.get("package").isnil()) env.get("package").get("loaded").set("bit32", t);
return t; return t;
} }

View File

@@ -82,7 +82,7 @@ public class CoroutineLib extends TwoArgFunction {
coroutine.set("yield", new yield()); coroutine.set("yield", new yield());
coroutine.set("wrap", new wrap()); coroutine.set("wrap", new wrap());
env.set("coroutine", coroutine); env.set("coroutine", coroutine);
env.get("package").get("loaded").set("coroutine", coroutine); if (!env.get("package").isnil()) env.get("package").get("loaded").set("coroutine", coroutine);
return coroutine; return coroutine;
} }

View File

@@ -135,7 +135,7 @@ public class DebugLib extends TwoArgFunction {
debug.set("upvalueid", new upvalueid()); debug.set("upvalueid", new upvalueid());
debug.set("upvaluejoin", new upvaluejoin()); debug.set("upvaluejoin", new upvaluejoin());
env.set("debug", debug); env.set("debug", debug);
env.get("package").get("loaded").set("debug", debug); if (!env.get("package").isnil()) env.get("package").get("loaded").set("debug", debug);
return debug; return debug;
} }

View File

@@ -256,7 +256,7 @@ public class IoLib extends TwoArgFunction {
// return the table // return the table
env.set("io", t); env.set("io", t);
env.get("package").get("loaded").set("io", t); if (!env.get("package").isnil()) env.get("package").get("loaded").set("io", t);
return t; return t;
} }

View File

@@ -125,7 +125,7 @@ public class MathLib extends TwoArgFunction {
math.set("sqrt", new sqrt()); math.set("sqrt", new sqrt());
math.set("tan", new tan()); math.set("tan", new tan());
env.set("math", math); env.set("math", math);
env.get("package").get("loaded").set("math", math); if (!env.get("package").isnil()) env.get("package").get("loaded").set("math", math);
return math; return math;
} }

View File

@@ -132,7 +132,7 @@ public class OsLib extends TwoArgFunction {
for (int i = 0; i < NAMES.length; ++i) for (int i = 0; i < NAMES.length; ++i)
os.set(NAMES[i], new OsLibFunc(i, NAMES[i])); os.set(NAMES[i], new OsLibFunc(i, NAMES[i]));
env.set("os", os); env.set("os", os);
env.get("package").get("loaded").set("os", os); if (!env.get("package").isnil()) env.get("package").get("loaded").set("os", os);
return os; return os;
} }

View File

@@ -24,8 +24,8 @@ package org.luaj.vm2.lib;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import org.luaj.vm2.LuaClosure;
import org.luaj.vm2.Buffer; import org.luaj.vm2.Buffer;
import org.luaj.vm2.LuaClosure;
import org.luaj.vm2.LuaString; import org.luaj.vm2.LuaString;
import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue; import org.luaj.vm2.LuaValue;
@@ -99,7 +99,7 @@ public class StringLib extends TwoArgFunction {
string.set("upper", new upper()); string.set("upper", new upper());
env.set("string", string); env.set("string", string);
env.get("package").get("loaded").set("string", string); if (!env.get("package").isnil()) env.get("package").get("loaded").set("string", string);
if (LuaString.s_metatable == null) { if (LuaString.s_metatable == null) {
LuaString.s_metatable = LuaValue.tableOf(new LuaValue[] { INDEX, string }); LuaString.s_metatable = LuaValue.tableOf(new LuaValue[] { INDEX, string });
} }

View File

@@ -70,7 +70,7 @@ public class TableLib extends TwoArgFunction {
table.set("sort", new sort()); table.set("sort", new sort());
table.set("unpack", new unpack()); table.set("unpack", new unpack());
env.set("table", table); env.set("table", table);
env.get("package").get("loaded").set("table", table); if (!env.get("package").isnil()) env.get("package").get("loaded").set("table", table);
return NIL; return NIL;
} }

View File

@@ -112,7 +112,7 @@ public class LuajavaLib extends VarArgFunction {
LuaTable t = new LuaTable(); LuaTable t = new LuaTable();
bind( t, this.getClass(), NAMES, BINDCLASS ); bind( t, this.getClass(), NAMES, BINDCLASS );
env.set("luajava", t); env.set("luajava", t);
env.get("package").get("loaded").set("luajava", t); if (!env.get("package").isnil()) env.get("package").get("loaded").set("luajava", t);
return t; return t;
} }
case BINDCLASS: { case BINDCLASS: {