* LuaTeX incompatible with Lua
@ 2019-11-21 7:17 Henri Menke
2019-11-21 7:43 ` Henri Menke
2019-11-21 8:18 ` Hans Hagen
0 siblings, 2 replies; 3+ messages in thread
From: Henri Menke @ 2019-11-21 7:17 UTC (permalink / raw)
To: mailing list for ConTeXt users
Dear list,
The following Lua script behaves differently when executed in Lua vs.
LuaTeX.
print(os.execute("date"))
It seems that the definition of os_execute in loslibext.c was copied
over from Lua 5.1 and not adapted to newer versions.
$ lua5.1 test.lua
0
$ lua5.2 test.lua
true exit 0
$ lua5.3 test.lua
true exit 0
$ texlua test.lua
0
$ luajit test.lua
0
$ texluajit test.lua
0
As you can see from the example, this comes with the additional
complication that LuaJIT has Lua 5.1 behaviour and should also retain
that.
Cheers, Henri
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: LuaTeX incompatible with Lua
2019-11-21 7:17 LuaTeX incompatible with Lua Henri Menke
@ 2019-11-21 7:43 ` Henri Menke
2019-11-21 8:18 ` Hans Hagen
1 sibling, 0 replies; 3+ messages in thread
From: Henri Menke @ 2019-11-21 7:43 UTC (permalink / raw)
To: mailing list for ConTeXt users
Below I include a suggestion on how to do this sort of version agnostic.
Cheers, Henri
Live example on Wandbox:
https://wandbox.org/permlink/jEn9kNnPB0t5rwjP
---
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <assert.h>
#include <stdio.h>
static int (*lua_os_execute)(lua_State *L) = NULL;
static int os_execute(lua_State *L) {
// Do whatever
printf("Hello Hans!\n");
// Safeguard
assert(lua_os_execute != NULL);
// Return wrapped
return lua_os_execute(L);
}
LUAMOD_API int luaopen_oslibext(lua_State *L) {
lua_getglobal(L, "os");
// Get the address of the original function
if (lua_os_execute == NULL) {
lua_getfield(L, -1, "execute");
lua_os_execute = lua_tocfunction(L, -1);
lua_pop(L, 1);
}
// Push the new function to overwrite the old one
lua_pushcfunction(L, os_execute);
lua_setfield(L, -2, "execute");
return 1;
}
int main(void) {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
luaopen_oslibext(L);
if (luaL_dostring(L, "os.execute([[date]])") != 0) {
fprintf(stderr, "%s", lua_tostring(L, -1));
lua_pop(L, 1);
}
lua_close(L);
}
On 11/21/19 8:17 PM, Henri Menke wrote:
> Dear list,
>
> The following Lua script behaves differently when executed in Lua vs.
> LuaTeX.
>
> print(os.execute("date"))
>
> It seems that the definition of os_execute in loslibext.c was copied
> over from Lua 5.1 and not adapted to newer versions.
>
> $ lua5.1 test.lua
> 0
> $ lua5.2 test.lua
> true exit 0
> $ lua5.3 test.lua
> true exit 0
> $ texlua test.lua
> 0
> $ luajit test.lua
> 0
> $ texluajit test.lua
> 0
>
> As you can see from the example, this comes with the additional
> complication that LuaJIT has Lua 5.1 behaviour and should also retain
> that.
>
> Cheers, Henri
>
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: LuaTeX incompatible with Lua
2019-11-21 7:17 LuaTeX incompatible with Lua Henri Menke
2019-11-21 7:43 ` Henri Menke
@ 2019-11-21 8:18 ` Hans Hagen
1 sibling, 0 replies; 3+ messages in thread
From: Hans Hagen @ 2019-11-21 8:18 UTC (permalink / raw)
To: mailing list for ConTeXt users, Henri Menke
On 11/21/2019 8:17 AM, Henri Menke wrote:
> Dear list,
>
> The following Lua script behaves differently when executed in Lua vs.
> LuaTeX.
>
> print(os.execute("date"))
>
> It seems that the definition of os_execute in loslibext.c was copied
> over from Lua 5.1 and not adapted to newer versions.
>
> $ lua5.1 test.lua
> 0
> $ lua5.2 test.lua
> true exit 0
> $ lua5.3 test.lua
> true exit 0
> $ texlua test.lua
> 0
> $ luajit test.lua
> 0
> $ texluajit test.lua
> 0
>
> As you can see from the example, this comes with the additional
> complication that LuaJIT has Lua 5.1 behaviour and should also retain
> that.
Indeed, the old interface was kept (also for compatibility reasons as
lua is used for scripts in texlive etc).
If one used lua as well as luatex as lua engine for the same script one
can write a wrapper if needed (I have been thinking of that on context
but again it would also mean adapting older scripts laying around.)
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-21 8:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21 7:17 LuaTeX incompatible with Lua Henri Menke
2019-11-21 7:43 ` Henri Menke
2019-11-21 8:18 ` Hans Hagen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).