summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/linit.js2
-rw-r--r--src/liolib.js26
-rw-r--r--src/lualib.js2
3 files changed, 29 insertions, 1 deletions
diff --git a/src/linit.js b/src/linit.js
index 3d18e2f..925b55a 100644
--- a/src/linit.js
+++ b/src/linit.js
@@ -10,6 +10,7 @@ const lstrlib = require('./lstrlib.js');
const ltablib = require('./ltablib.js');
const lutf8lib = require('./lutf8lib.js');
const ldblib = require('./ldblib.js');
+const liolib = require('./liolib.js');
const loslib = require('./loslib.js');
const lualib = require('./lualib.js');
@@ -17,6 +18,7 @@ const loadedlibs = {
[lualib.LUA_COLIBNAME]: lcorolib.luaopen_coroutine,
[lualib.LUA_DBLIBNAME]: ldblib.luaopen_debug,
[lualib.LUA_MATHLIBNAME]: lmathlib.luaopen_math,
+ [lualib.LUA_IOLIBNAME]: liolib.luaopen_io,
[lualib.LUA_OSLIBNAME]: loslib.luaopen_os,
[lualib.LUA_STRLIBNAME]: lstrlib.luaopen_string,
[lualib.LUA_TABLIBNAME]: ltablib.luaopen_table,
diff --git a/src/liolib.js b/src/liolib.js
new file mode 100644
index 0000000..22dc2e8
--- /dev/null
+++ b/src/liolib.js
@@ -0,0 +1,26 @@
+"use strict";
+
+const lua = require('./lua.js');
+const lauxlib = require('./lauxlib.js');
+
+const iolib = {
+};
+
+const flib = {
+};
+
+const createmeta = function(L) {
+ lauxlib.luaL_newmetatable(L, lauxlib.LUA_FILEHANDLE); /* create metatable for file handles */
+ lua.lua_pushvalue(L, -1); /* push metatable */
+ lua.lua_setfield(L, -2, lua.to_luastring("__index", true)); /* metatable.__index = metatable */
+ lauxlib.luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
+ lua.lua_pop(L, 1); /* pop new metatable */
+};
+
+const luaopen_io = function(L) {
+ lauxlib.luaL_newlib(L, iolib);
+ createmeta(L);
+ return 1;
+};
+
+module.exports.luaopen_io = luaopen_io;
diff --git a/src/lualib.js b/src/lualib.js
index 327673e..b0bd253 100644
--- a/src/lualib.js
+++ b/src/lualib.js
@@ -16,7 +16,7 @@ module.exports[LUA_TABLIBNAME] = require("./ltablib.js").luaopen_table;
const LUA_IOLIBNAME = "io";
module.exports.LUA_IOLIBNAME = LUA_IOLIBNAME;
-// module.exports[LUA_IOLIBNAME] = require("./liolib.js").luaopen_io;
+module.exports[LUA_IOLIBNAME] = require("./liolib.js").luaopen_io;
const LUA_OSLIBNAME = "os";
module.exports.LUA_OSLIBNAME = LUA_OSLIBNAME;