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 ### */
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;
+}
}
extern const char regex_id[];
+extern char lua_ver[]; /* nhlua.c */
/*
* makedefs should put the first token into dat/options; we'll substitute
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" */
};
/*
{
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 */