aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-02-17 11:12:26 +1100
committerdaurnimator <quae@daurnimator.com>2018-02-17 11:17:54 +1100
commit123dfc7ca0cea702a552bc24614e66b4144cca07 (patch)
treecb8d0b2afd0fb734cddf65ad1d7fae10b338d718
parentaa6a466bea35db093a0131dce0612a4de428306c (diff)
downloadfengari-123dfc7ca0cea702a552bc24614e66b4144cca07.tar.gz
fengari-123dfc7ca0cea702a552bc24614e66b4144cca07.tar.bz2
fengari-123dfc7ca0cea702a552bc24614e66b4144cca07.zip
Rename cpath to jspath
-rw-r--r--README.md5
-rw-r--r--src/defs.js42
-rw-r--r--src/loadlib.js74
-rw-r--r--src/lua.js2
-rw-r--r--tests/test-suite/attrib.js2
5 files changed, 63 insertions, 62 deletions
diff --git a/README.md b/README.md
index 959b4f8..fed507c 100644
--- a/README.md
+++ b/README.md
@@ -68,13 +68,14 @@ In the browser `require` and `package.loadlib` try to find a file by making sync
- [Weak tables](http://www.lua.org/manual/5.3/manual.html#2.5.2)
-### _Differences_ from C API
+### _Differences_
+- `package.jspath` instead of `package.cpath`
+- `LUA_JSPATH_DEFAULT` instead of `LUA_CPATH_DEFAULT` (and contains .js extensions rather than .so or .dll extensions)
- `lua_tointegerx` and `lua_tonumberx` do not have out-parameters indicating conversion success. Instead, ``false`` is returned when conversion fails.
- `luaL_execresult` takes an extra argument: an error object. The error object should have a fields `status`, `signal` and `errno`.
- `luaL_fileresult` takes an extra argument: an error object. The error object should have a field `errno`.
-
## Extensions
### `dv = lua_todataview(L, idx)`
diff --git a/src/defs.js b/src/defs.js
index f17c65c..5b0081b 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -339,7 +339,7 @@ module.exports.LUA_EXEC_DIR = LUA_EXEC_DIR;
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
** Lua libraries.
-@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
+@@ LUA_JSPATH_DEFAULT is the default path that Lua uses to look for
** C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
@@ -355,20 +355,20 @@ if (typeof process === "undefined") {
const LUA_LDIR = "./lua/" + LUA_VDIR + "/";
module.exports.LUA_LDIR = LUA_LDIR;
- const LUA_CDIR = "./lua/" + LUA_VDIR + "/";
- module.exports.LUA_CDIR = LUA_CDIR;
+ const LUA_JSDIR = "./lua/" + LUA_VDIR + "/";
+ module.exports.LUA_JSDIR = LUA_JSDIR;
const LUA_PATH_DEFAULT = to_luastring(
LUA_LDIR + "?.lua;" + LUA_LDIR + "?/init.lua;" +
- LUA_CDIR + "?.lua;" + LUA_CDIR + "?/init.lua;" +
+ LUA_JSDIR + "?.lua;" + LUA_JSDIR + "?/init.lua;" +
"./?.lua;./?/init.lua"
);
module.exports.LUA_PATH_DEFAULT = LUA_PATH_DEFAULT;
- const LUA_CPATH_DEFAULT = to_luastring(
- LUA_CDIR + "?.js;" + LUA_CDIR + "loadall.js;./?.js"
+ const LUA_JSPATH_DEFAULT = to_luastring(
+ LUA_JSDIR + "?.js;" + LUA_JSDIR + "loadall.js;./?.js"
);
- module.exports.LUA_CPATH_DEFAULT = LUA_CPATH_DEFAULT;
+ module.exports.LUA_JSPATH_DEFAULT = LUA_JSPATH_DEFAULT;
} else if (require('os').platform() === 'win32') {
const LUA_DIRSEP = "\\";
module.exports.LUA_DIRSEP = LUA_DIRSEP;
@@ -380,26 +380,26 @@ if (typeof process === "undefined") {
const LUA_LDIR = "!\\lua\\";
module.exports.LUA_LDIR = LUA_LDIR;
- const LUA_CDIR = "!\\";
- module.exports.LUA_CDIR = LUA_CDIR;
+ const LUA_JSDIR = "!\\";
+ module.exports.LUA_JSDIR = LUA_JSDIR;
const LUA_SHRDIR = "!\\..\\share\\lua\\" + LUA_VDIR + "\\";
module.exports.LUA_SHRDIR = LUA_SHRDIR;
const LUA_PATH_DEFAULT = to_luastring(
LUA_LDIR + "?.lua;" + LUA_LDIR + "?\\init.lua;" +
- LUA_CDIR + "?.lua;" + LUA_CDIR + "?\\init.lua;" +
+ LUA_JSDIR + "?.lua;" + LUA_JSDIR + "?\\init.lua;" +
LUA_SHRDIR + "?.lua;" + LUA_SHRDIR + "?\\init.lua;" +
".\\?.lua;.\\?\\init.lua"
);
module.exports.LUA_PATH_DEFAULT = LUA_PATH_DEFAULT;
- const LUA_CPATH_DEFAULT = to_luastring(
- LUA_CDIR + "?.js;" +
- LUA_CDIR + "..\\lib\\lua\\" + LUA_VDIR + "\\?.js;" +
- LUA_CDIR + "loadall.js;.\\?.js"
+ const LUA_JSPATH_DEFAULT = to_luastring(
+ LUA_JSDIR + "?.js;" +
+ LUA_JSDIR + "..\\lib\\lua\\" + LUA_VDIR + "\\?.js;" +
+ LUA_JSDIR + "loadall.js;.\\?.js"
);
- module.exports.LUA_CPATH_DEFAULT = LUA_CPATH_DEFAULT;
+ module.exports.LUA_JSPATH_DEFAULT = LUA_JSPATH_DEFAULT;
} else {
const LUA_DIRSEP = "/";
module.exports.LUA_DIRSEP = LUA_DIRSEP;
@@ -410,20 +410,20 @@ if (typeof process === "undefined") {
const LUA_LDIR = LUA_ROOT + "share/lua/" + LUA_VDIR + "/";
module.exports.LUA_LDIR = LUA_LDIR;
- const LUA_CDIR = LUA_ROOT + "lib/lua/" + LUA_VDIR + "/";
- module.exports.LUA_CDIR = LUA_CDIR;
+ const LUA_JSDIR = LUA_ROOT + "lib/lua/" + LUA_VDIR + "/";
+ module.exports.LUA_JSDIR = LUA_JSDIR;
const LUA_PATH_DEFAULT = to_luastring(
LUA_LDIR + "?.lua;" + LUA_LDIR + "?/init.lua;" +
- LUA_CDIR + "?.lua;" + LUA_CDIR + "?/init.lua;" +
+ LUA_JSDIR + "?.lua;" + LUA_JSDIR + "?/init.lua;" +
"./?.lua;./?/init.lua"
);
module.exports.LUA_PATH_DEFAULT = LUA_PATH_DEFAULT;
- const LUA_CPATH_DEFAULT = to_luastring(
- LUA_CDIR + "?.js;" + LUA_CDIR + "loadall.js;./?.js"
+ const LUA_JSPATH_DEFAULT = to_luastring(
+ LUA_JSDIR + "?.js;" + LUA_JSDIR + "loadall.js;./?.js"
);
- module.exports.LUA_CPATH_DEFAULT = LUA_CPATH_DEFAULT;
+ module.exports.LUA_JSPATH_DEFAULT = LUA_JSPATH_DEFAULT;
}
module.exports.LUA_AUTHORS = LUA_AUTHORS;
diff --git a/src/loadlib.js b/src/loadlib.js
index 99540e4..147b942 100644
--- a/src/loadlib.js
+++ b/src/loadlib.js
@@ -1,9 +1,9 @@
"use strict";
const {
- LUA_CPATH_DEFAULT,
LUA_DIRSEP,
LUA_EXEC_DIR,
+ LUA_JSPATH_DEFAULT,
LUA_OK,
LUA_PATH_DEFAULT,
LUA_PATH_MARK,
@@ -87,29 +87,29 @@ const global_env = (function() {
}
})();
-const CLIBS = to_luastring("__CLIBS__");
-const LUA_PATH_VAR = "LUA_PATH";
-const LUA_CPATH_VAR = "LUA_CPATH";
+const JSLIBS = to_luastring("__JSLIBS__");
+const LUA_PATH_VAR = "LUA_PATH";
+const LUA_JSPATH_VAR = "LUA_JSPATH";
-const LUA_IGMARK = "-";
+const LUA_IGMARK = "-";
/*
** LUA_CSUBSEP is the character that replaces dots in submodule names
-** when searching for a C loader.
+** when searching for a JS loader.
** LUA_LSUBSEP is the character that replaces dots in submodule names
** when searching for a Lua loader.
*/
-const LUA_CSUBSEP = LUA_DIRSEP;
-const LUA_LSUBSEP = LUA_DIRSEP;
+const LUA_CSUBSEP = LUA_DIRSEP;
+const LUA_LSUBSEP = LUA_DIRSEP;
-/* prefix for open functions in C libraries */
-const LUA_POF = to_luastring("luaopen_");
+/* prefix for open functions in JS libraries */
+const LUA_POF = to_luastring("luaopen_");
-/* separator for open functions in C libraries */
-const LUA_OFSEP = to_luastring("_");
-const LIB_FAIL = "open";
+/* separator for open functions in JS libraries */
+const LUA_OFSEP = to_luastring("_");
+const LIB_FAIL = "open";
-const AUXMARK = to_luastring("\x01");
+const AUXMARK = to_luastring("\x01");
/*
@@ -236,11 +236,11 @@ const ERRFUNC = 2;
** errors, return an error code and an error message in the stack.
*/
const lookforfunc = function(L, path, sym) {
- let reg = checkclib(L, path); /* check loaded C libraries */
+ let reg = checkjslib(L, path); /* check loaded JS libraries */
if (reg === null) { /* must load library? */
reg = lsys_load(L, path, sym[0] === '*'.charCodeAt(0)); /* a global symbols if 'sym'=='*' */
if (reg === null) return ERRLIB; /* unable to load library */
- addtoclib(L, path, reg);
+ addtojslib(L, path, reg);
}
if (sym[0] === '*'.charCodeAt(0)) { /* loading only library (no function)? */
lua_pushboolean(L, 1); /* return 'true' */
@@ -305,27 +305,27 @@ const setpath = function(L, fieldname, envname, dft) {
};
/*
-** return registry.CLIBS[path]
+** return registry.JSLIBS[path]
*/
-const checkclib = function(L, path) {
- lua_rawgetp(L, LUA_REGISTRYINDEX, CLIBS);
+const checkjslib = function(L, path) {
+ lua_rawgetp(L, LUA_REGISTRYINDEX, JSLIBS);
lua_getfield(L, -1, path);
- let plib = lua_touserdata(L, -1); /* plib = CLIBS[path] */
- lua_pop(L, 2); /* pop CLIBS table and 'plib' */
+ let plib = lua_touserdata(L, -1); /* plib = JSLIBS[path] */
+ lua_pop(L, 2); /* pop JSLIBS table and 'plib' */
return plib;
};
/*
-** registry.CLIBS[path] = plib -- for queries
-** registry.CLIBS[#CLIBS + 1] = plib -- also keep a list of all libraries
+** registry.JSLIBS[path] = plib -- for queries
+** registry.JSLIBS[#JSLIBS + 1] = plib -- also keep a list of all libraries
*/
-const addtoclib = function(L, path, plib) {
- lua_rawgetp(L, LUA_REGISTRYINDEX, CLIBS);
+const addtojslib = function(L, path, plib) {
+ lua_rawgetp(L, LUA_REGISTRYINDEX, JSLIBS);
lua_pushlightuserdata(L, plib);
lua_pushvalue(L, -1);
- lua_setfield(L, -3, path); /* CLIBS[path] = plib */
- lua_rawseti(L, -2, luaL_len(L, -2) + 1); /* CLIBS[#CLIBS + 1] = plib */
- lua_pop(L, 1); /* pop CLIBS table */
+ lua_setfield(L, -3, path); /* JSLIBS[path] = plib */
+ lua_rawseti(L, -2, luaL_len(L, -2) + 1); /* JSLIBS[#JSLIBS + 1] = plib */
+ lua_pop(L, 1); /* pop JSLIBS table */
};
const pushnexttemplate = function(L, path) {
@@ -420,7 +420,7 @@ const loadfunc = function(L, filename, modname) {
const searcher_C = function(L) {
let name = luaL_checkstring(L, 1);
- let filename = findfile(L, name, to_luastring("cpath", true), to_luastring(LUA_CSUBSEP, true));
+ let filename = findfile(L, name, to_luastring("jspath", true), to_luastring(LUA_CSUBSEP, true));
if (filename === null) return 1; /* module not found in this path */
return checkload(L, (loadfunc(L, filename, name) === 0), filename);
};
@@ -431,7 +431,7 @@ const searcher_Croot = function(L) {
let stat;
if (p < 0) return 0; /* is root */
lua_pushlstring(L, name, p);
- let filename = findfile(L, lua_tostring(L, -1), to_luastring("cpath", true), to_luastring(LUA_CSUBSEP, true));
+ let filename = findfile(L, lua_tostring(L, -1), to_luastring("jspath", true), to_luastring(LUA_CSUBSEP, true));
if (filename === null) return 1; /* root not found */
if ((stat = loadfunc(L, filename, name)) !== 0) {
if (stat != ERRFUNC)
@@ -545,23 +545,23 @@ const createsearcherstable = function(L) {
};
/*
-** create table CLIBS to keep track of loaded C libraries,
+** create table JSLIBS to keep track of loaded JS libraries,
** setting a finalizer to close all libraries when closing state.
*/
-const createclibstable = function(L) {
- lua_newtable(L); /* create CLIBS table */
- lua_createtable(L, 0, 1); /* create metatable for CLIBS */
+const createjslibstable = function(L) {
+ lua_newtable(L); /* create JSLIBS table */
+ lua_createtable(L, 0, 1); /* create metatable for JSLIBS */
lua_setmetatable(L, -2);
- lua_rawsetp(L, LUA_REGISTRYINDEX, CLIBS); /* set CLIBS table in registry */
+ lua_rawsetp(L, LUA_REGISTRYINDEX, JSLIBS); /* set JSLIBS table in registry */
};
const luaopen_package = function(L) {
- createclibstable(L);
+ createjslibstable(L);
luaL_newlib(L, pk_funcs); /* create 'package' table */
createsearcherstable(L);
/* set paths */
setpath(L, to_luastring("path", true), LUA_PATH_VAR, LUA_PATH_DEFAULT);
- setpath(L, to_luastring("cpath", true), LUA_CPATH_VAR, LUA_CPATH_DEFAULT);
+ setpath(L, to_luastring("jspath", true), LUA_JSPATH_VAR, LUA_JSPATH_DEFAULT);
/* store config information */
lua_pushliteral(L, LUA_DIRSEP + "\n" + LUA_PATH_SEP + "\n" + LUA_PATH_MARK + "\n" +
LUA_EXEC_DIR + "\n" + LUA_IGMARK + "\n");
diff --git a/src/lua.js b/src/lua.js
index 770669e..6de7553 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -71,8 +71,8 @@ module.exports.LUA_YIELD = defs.thread_status.LUA_YIELD;
module.exports.lua_Debug = defs.lua_Debug;
module.exports.lua_upvalueindex = defs.lua_upvalueindex;
module.exports.LUA_CDIR = defs.LUA_CDIR;
-module.exports.LUA_CPATH_DEFAULT = defs.LUA_CPATH_DEFAULT;
module.exports.LUA_EXEC_DIR = defs.LUA_EXEC_DIR;
+module.exports.LUA_JSPATH_DEFAULT = defs.LUA_JSPATH_DEFAULT;
module.exports.LUA_LDIR = defs.LUA_LDIR;
module.exports.LUA_PATH_DEFAULT = defs.LUA_PATH_DEFAULT;
module.exports.LUA_PATH_MARK = defs.LUA_PATH_MARK;
diff --git a/tests/test-suite/attrib.js b/tests/test-suite/attrib.js
index 7445a5e..5053a31 100644
--- a/tests/test-suite/attrib.js
+++ b/tests/test-suite/attrib.js
@@ -17,7 +17,7 @@ test("[test-suite] attrib: testing require", function (t) {
assert(require"coroutine" == coroutine)
assert(type(package.path) == "string")
- assert(type(package.cpath) == "string")
+ assert(type(package.jspath) == "string")
assert(type(package.loaded) == "table")
assert(type(package.preload) == "table")