diff --git a/include/extern.h b/include/extern.h index 9c8de1b74..7e9a62c41 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1692,6 +1692,7 @@ E int FDECL(get_table_boolean_opt, (lua_State *, const char *, int)); E int FDECL(get_table_option, (lua_State *, const char *, const char *, const char *const *)); E int FDECL(str_lines_max_width, (const char *)); E char *FDECL(stripdigits, (char *)); +E const char *NDECL(get_lua_version); #endif /* !CROSSCOMPILE || CROSSCOMPILE_TARGET */ /* ### nhregex.c ### */ diff --git a/src/nhlua.c b/src/nhlua.c index 7c20d9b98..c66cd8039 100644 --- a/src/nhlua.c +++ b/src/nhlua.c @@ -904,3 +904,25 @@ const char *name; return ret; } + +const char * +get_lua_version() +{ + size_t len; + const char *vs = (const char *) 0; + lua_State *L; + + if (g.lua_ver[0] == 0) { + L = nhl_init(); + + if (L) { + lua_getglobal(L, "_VERSION"); + if (lua_isstring(L, -1)) + vs = lua_tolstring (L, -1, &len); + if (vs && (int) len < sizeof g.lua_ver - 1) + Strcpy(g.lua_ver, vs); + } + lua_close(L); + } + return (const char *) g.lua_ver; +} diff --git a/src/version.c b/src/version.c index c4040c1bc..4939f9f14 100644 --- a/src/version.c +++ b/src/version.c @@ -290,6 +290,7 @@ boolean pastebuf; } extern const char regex_id[]; +extern char lua_ver[]; /* nhlua.c */ /* * makedefs should put the first token into dat/options; we'll substitute @@ -303,7 +304,7 @@ static struct rt_opt { const char *token, *value; } rt_opts[] = { { ":PATMATCH:", regex_id }, - { ":LUAVERSION:", " 5.3.5"}, /* plan is to get this directly from Lua */ + { ":LUAVERSION:", (const char *) g.lua_ver + 3 }, /* +3 skip past "Lua" */ }; /* @@ -318,8 +319,11 @@ char *buf; { int i; + if (!g.lua_ver[0]) + get_lua_version(); + for (i = 0; i < SIZE(rt_opts); ++i) { - if (strstri(buf, rt_opts[i].token)) + if (strstri(buf, rt_opts[i].token) && *rt_opts[i].value) (void) strsubst(buf, rt_opts[i].token, rt_opts[i].value); /* we don't break out of the loop after a match; there might be other matches on the same line */