|
@@ -711,6 +711,16 @@ int w_load(lua_State *L)
|
|
|
{
|
|
|
std::string filename = std::string(luaL_checkstring(L, 1));
|
|
|
|
|
|
+ Filesystem::LoadMode loadMode = Filesystem::LOADMODE_ANY;
|
|
|
+
|
|
|
+ if (!lua_isnoneornil(L, 2))
|
|
|
+ {
|
|
|
+ const char *mode = luaL_checkstring(L, 2);
|
|
|
+
|
|
|
+ if (!Filesystem::getConstant(mode, loadMode))
|
|
|
+ return luax_enumerror(L, "load mode", Filesystem::getConstants(loadMode), mode);
|
|
|
+ }
|
|
|
+
|
|
|
Data *data = nullptr;
|
|
|
try
|
|
|
{
|
|
@@ -721,7 +731,24 @@ int w_load(lua_State *L)
|
|
|
return luax_ioError(L, "%s", e.what());
|
|
|
}
|
|
|
|
|
|
- int status = luaL_loadbuffer(L, (const char *)data->getData(), data->getSize(), ("@" + filename).c_str());
|
|
|
+ int status;
|
|
|
+
|
|
|
+#if (LUA_VERSION_NUM > 501) || defined(LUA_JITLIBNAME)
|
|
|
+ // LuaJIT support this Lua 5.2 function.
|
|
|
+ const char *mode;
|
|
|
+ Filesystem::getConstant(loadMode, mode);
|
|
|
+
|
|
|
+ status = luaL_loadbufferx(L, (const char *)data->getData(), data->getSize(), ("@" + filename).c_str(), mode);
|
|
|
+#else
|
|
|
+ if (loadMode == Filesystem::LOADMODE_ANY)
|
|
|
+ status = luaL_loadbuffer(L, (const char *)data->getData(), data->getSize(), ("@" + filename).c_str());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Unsupported
|
|
|
+ data->release();
|
|
|
+ return luaL_error(L, "only \"bt\" is supported on this Lua interpreter\n");
|
|
|
+ }
|
|
|
+#endif
|
|
|
|
|
|
data->release();
|
|
|
|