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/liolib.js | |
parent | 31c5b59ab91fa94a62bc958d30060625acff4afe (diff) | |
download | fengari-f93607f954c002b251fba4e0b85493e0b2b619b4.tar.gz fengari-f93607f954c002b251fba4e0b85493e0b2b619b4.tar.bz2 fengari-f93607f954c002b251fba4e0b85493e0b2b619b4.zip |
Add (empty) io library
Diffstat (limited to 'src/liolib.js')
-rw-r--r-- | src/liolib.js | 26 |
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; |