get lua version from lua itself
This commit is contained in:
@@ -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 ### */
|
||||
|
||||
22
src/nhlua.c
22
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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user