| 2411 | } |
| 2412 | |
| 2413 | DISABLE_WARNING_CONDEXPR_IS_CONSTANT |
| 2414 | |
| 2415 | const char * |
| 2416 | get_lua_version(void) |
| 2417 | { |
| 2418 | nhl_sandbox_info sbi = { NHL_SB_VERSION, 1 * 1024 * 1024, 0, |
| 2419 | 1 * 1024 * 1024 }; |
| 2420 | |
| 2421 | if (gl.lua_ver[0] == 0) { |
| 2422 | lua_State *L = nhl_init(&sbi); |
| 2423 | |
| 2424 | if (L) { |
| 2425 | size_t len = 0; |
| 2426 | const char *vs = (const char *) 0; |
| 2427 | |
| 2428 | /* LUA_VERSION yields "<major>.<minor>" although we check to see |
| 2429 | whether it is "Lua-<major>.<minor>" and strip prefix if so; |
| 2430 | LUA_RELEASE is <LUA_VERSION>.<LUA_VERSION_RELEASE> but doesn't |
| 2431 | get set up as a lua global */ |
| 2432 | lua_getglobal(L, "_RELEASE"); |
| 2433 | if (lua_isstring(L, -1)) |
| 2434 | vs = lua_tolstring(L, -1, &len); |
| 2435 | #ifdef LUA_RELEASE |
| 2436 | else |
| 2437 | vs = LUA_RELEASE, len = strlen(vs); |
| 2438 | #endif |
| 2439 | if (!vs) { |
| 2440 | lua_getglobal(L, "_VERSION"); |
| 2441 | if (lua_isstring(L, -1)) |
| 2442 | vs = lua_tolstring(L, -1, &len); |
| 2443 | #ifdef LUA_VERSION |
| 2444 | else |
| 2445 | vs = LUA_VERSION, len = strlen(vs); |
| 2446 | #endif |
| 2447 | } |
| 2448 | if (vs && len < sizeof gl.lua_ver) { |
| 2449 | if (!strncmpi(vs, "Lua", 3)) { |
| 2450 | vs += 3; |
| 2451 | if (*vs == '-' || *vs == ' ') |
| 2452 | vs += 1; |
| 2453 | } |
| 2454 | Strcpy(gl.lua_ver, vs); |
| 2455 | } |
| 2456 | } |
| 2457 | nhl_done(L); |
| 2458 | #ifdef LUA_COPYRIGHT |
| 2459 | if (sizeof LUA_COPYRIGHT <= sizeof gl.lua_copyright) |
| 2460 | Strcpy(gl.lua_copyright, LUA_COPYRIGHT); |
| 2461 | #endif |
| 2462 | } |
| 2463 | return (const char *) gl.lua_ver; |
| 2464 | } |
| 2465 | |
| 2466 | RESTORE_WARNING_CONDEXPR_IS_CONSTANT |
| 2467 |
no test coverage detected