summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/lua/luastuff.w
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/lua/luastuff.w')
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/luastuff.w73
1 files changed, 50 insertions, 23 deletions
diff --git a/Build/source/texk/web2c/luatexdir/lua/luastuff.w b/Build/source/texk/web2c/luatexdir/lua/luastuff.w
index 17789d04d3c..e9942881baf 100644
--- a/Build/source/texk/web2c/luatexdir/lua/luastuff.w
+++ b/Build/source/texk/web2c/luatexdir/lua/luastuff.w
@@ -19,7 +19,7 @@
@ @c
static const char _svn_version[] =
- "$Id: luastuff.w 4730 2014-01-03 14:44:14Z taco $"
+ "$Id: luastuff.w 4877 2014-03-14 01:26:05Z luigi $"
"$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/lua/luastuff.w $";
#include "ptexlib.h"
@@ -33,7 +33,7 @@ int luastate_bytes = 0;
int lua_active = 0;
@ @c
-void make_table(lua_State * L, const char *tab, const char *getfunc,
+void make_table(lua_State * L, const char *tab, const char *mttab, const char *getfunc,
const char *setfunc)
{
/* make the table *//* |[{<tex>}]| */
@@ -44,7 +44,7 @@ void make_table(lua_State * L, const char *tab, const char *getfunc,
lua_pushstring(L, tab); /* |[{<tex>},"dimen"]| */
lua_gettable(L, -2); /* |[{<tex>},{<dimen>}]| */
/* make the meta entries */
- luaL_newmetatable(L, tab); /* |[{<tex>},{<dimen>},{<dimen_m>}]| */
+ luaL_newmetatable(L, mttab); /* |[{<tex>},{<dimen>},{<dimen_m>}]| */
lua_pushstring(L, "__index"); /* |[{<tex>},{<dimen>},{<dimen_m>},"__index"]| */
lua_pushstring(L, getfunc); /* |[{<tex>},{<dimen>},{<dimen_m>},"__index","getdimen"]| */
lua_gettable(L, -5); /* |[{<tex>},{<dimen>},{<dimen_m>},"__index",<tex.getdimen>]| */
@@ -92,6 +92,31 @@ static int my_luapanic(lua_State * L)
return 0;
}
+
+@ @c
+void luafunctioncall(int slot)
+{
+ int i ;
+ int stacktop = lua_gettop(Luas);
+ lua_active++;
+ lua_rawgeti(Luas, LUA_REGISTRYINDEX, lua_key_index(lua_functions));
+ lua_gettable(Luas, LUA_REGISTRYINDEX);
+ lua_rawgeti(Luas, -1,slot);
+ if (lua_isfunction(Luas,-1)) {
+ lua_pushcfunction(Luas, lua_traceback); /* push traceback function */
+ lua_insert(Luas, -2); /* put it under chunk */
+ lua_pushnumber(Luas, slot);
+ i = lua_pcall(Luas, 1, 0, -2);
+ if (i != 0) {
+ lua_gc(Luas, LUA_GCCOLLECT, 0);
+ Luas = luatex_error(Luas, (i == LUA_ERRRUN ? 0 : 1));
+ }
+ }
+ lua_settop(Luas,stacktop);
+ lua_active--;
+}
+
+
@ @c
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
@@ -360,7 +385,7 @@ int lua_traceback(lua_State * L)
}
@ @c
-static void luacall(int p, int nameptr, boolean is_string)
+static void luacall(int p, int nameptr, boolean is_string) /* hh-ls: optimized lua_id resolving */
{
LoadS ls;
int i;
@@ -390,18 +415,19 @@ static void luacall(int p, int nameptr, boolean is_string)
if (nameptr > 0) {
int l = 0; /* not used */
lua_id = tokenlist_to_cstring(nameptr, 1, &l);
+ i = lua_load(Luas, getS, &ls, lua_id, NULL);
+ xfree(lua_id);
} else if (nameptr < 0) {
- char *tmp = get_lua_name((nameptr + 65536));
- if (tmp != NULL)
- lua_id = xstrdup(tmp);
- else
- lua_id = xstrdup("\\latelua ");
+ lua_id = get_lua_name((nameptr + 65536));
+ if (lua_id != NULL) {
+ i = lua_load(Luas, getS, &ls, lua_id, NULL);
+ xfree(lua_id);
+ } else {
+ i = lua_load(Luas, getS, &ls, "\\latelua ", NULL);
+ }
} else {
- lua_id = xmalloc(20);
- snprintf((char *) lua_id, 20, "\\latelua ");
+ i = lua_load(Luas, getS, &ls, "\\latelua ", NULL);
}
-
- i = lua_load(Luas, getS, &ls, lua_id, NULL);
if (i != 0) {
Luas = luatex_error(Luas, (i == LUA_ERRSYNTAX ? 0 : 1));
} else {
@@ -416,7 +442,6 @@ static void luacall(int p, int nameptr, boolean is_string)
Luas = luatex_error(Luas, (i == LUA_ERRRUN ? 0 : 1));
}
}
- xfree(lua_id);
xfree(ls.s);
}
lua_active--;
@@ -436,7 +461,7 @@ void late_lua(PDF pdf, halfword p)
}
@ @c
-void luatokencall(int p, int nameptr)
+void luatokencall(int p, int nameptr) /* hh-ls: optimized lua_id resolving */
{
LoadS ls;
int i, l;
@@ -451,16 +476,19 @@ void luatokencall(int p, int nameptr)
if (ls.size > 0) {
if (nameptr > 0) {
lua_id = tokenlist_to_cstring(nameptr, 1, &l);
+ i = lua_load(Luas, getS, &ls, lua_id, NULL);
+ xfree(lua_id);
} else if (nameptr < 0) {
- char *tmp = get_lua_name((nameptr + 65536));
- if (tmp != NULL)
- lua_id = xstrdup(tmp);
- else
- lua_id = xstrdup("\\directlua ");
+ lua_id = get_lua_name((nameptr + 65536));
+ if (lua_id != NULL) {
+ i = lua_load(Luas, getS, &ls, lua_id, NULL);
+ xfree(lua_id);
+ } else {
+ i = lua_load(Luas, getS, &ls, "\\directlua ", NULL);
+ }
} else {
- lua_id = xstrdup("\\directlua ");
+ i = lua_load(Luas, getS, &ls, "\\directlua ", NULL);
}
- i = lua_load(Luas, getS, &ls, lua_id, NULL);
xfree(s);
if (i != 0) {
Luas = luatex_error(Luas, (i == LUA_ERRSYNTAX ? 0 : 1));
@@ -476,7 +504,6 @@ void luatokencall(int p, int nameptr)
Luas = luatex_error(Luas, (i == LUA_ERRRUN ? 0 : 1));
}
}
- xfree(lua_id);
}
lua_active--;
}