summaryrefslogtreecommitdiff
path: root/src/liolib.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/liolib.js')
-rw-r--r--src/liolib.js26
1 files changed, 26 insertions, 0 deletions
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;