diff options
author | daurnimator <quae@daurnimator.com> | 2017-04-25 19:01:45 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-04-26 21:30:58 +1000 |
commit | f93607f954c002b251fba4e0b85493e0b2b619b4 (patch) | |
tree | 0c4de91da925ff70a092a792659e95a69e751b8a /src | |
parent | 31c5b59ab91fa94a62bc958d30060625acff4afe (diff) | |
download | fengari-f93607f954c002b251fba4e0b85493e0b2b619b4.tar.gz fengari-f93607f954c002b251fba4e0b85493e0b2b619b4.tar.bz2 fengari-f93607f954c002b251fba4e0b85493e0b2b619b4.zip |
Add (empty) io library
Diffstat (limited to 'src')
-rw-r--r-- | src/linit.js | 2 | ||||
-rw-r--r-- | src/liolib.js | 26 | ||||
-rw-r--r-- | src/lualib.js | 2 |
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; |