| 419 | } |
| 420 | |
| 421 | ScriptVar ScriptVar::ReadVar(int index, bool with_metatable_index) |
| 422 | { |
| 423 | lua_init(); |
| 424 | |
| 425 | ScriptVar r; |
| 426 | |
| 427 | EXIT_IF(index == 0); |
| 428 | |
| 429 | // script_dbg_dump_stack(String::FromPrintf("script_read_var( %d )", index)); |
| 430 | |
| 431 | if (index < 0) |
| 432 | { |
| 433 | index = lua_gettop(g_lua_state) + index + 1; |
| 434 | } |
| 435 | |
| 436 | lua_pushvalue(g_lua_state, index); |
| 437 | |
| 438 | // printf("sizeof(lua_Integer) = %d\n", (int)sizeof(lua_Integer)); |
| 439 | // printf("LUA_INTEGER_FRMLEN = %s\n", LUA_INTEGER_FRMLEN); |
| 440 | // printf("LUA_MAXINTEGER = %" PRIi64"\n", (int64_t)LUA_MAXINTEGER); |
| 441 | // printf("LUA_MININTEGER = %" PRIi64"\n", (int64_t)LUA_MININTEGER); |
| 442 | |
| 443 | r.m_p->val_double = lua_tonumber(g_lua_state, -1); |
| 444 | r.m_p->val_bool = (lua_toboolean(g_lua_state, -1) != 0); |
| 445 | #if KYTY_LUA_VER == KYTY_LUA_5_3 |
| 446 | Read.m_p->val_integer = lua_tointeger(g_lua_state, -1); |
| 447 | #endif |
| 448 | r.m_p->val_string = String::FromUtf8(lua_tostring(g_lua_state, -1)); |
| 449 | r.m_p->val_userdata = lua_touserdata(g_lua_state, -1); |
| 450 | |
| 451 | r.m_p->is_c_function = (lua_iscfunction(g_lua_state, -1) != 0); |
| 452 | r.m_p->is_double = (lua_isnumber(g_lua_state, -1) != 0); |
| 453 | r.m_p->is_function = lua_isfunction(g_lua_state, -1); |
| 454 | #if KYTY_LUA_VER == KYTY_LUA_5_3 |
| 455 | Read.is_integer = lua_isinteger(g_lua_state, -1); |
| 456 | if (!Read.is_integer) |
| 457 | { |
| 458 | Read.is_integer = lua_tointeger(g_lua_state, -1) != 0 || lua_tostring(g_lua_state, -1) == String("0"); |
| 459 | } |
| 460 | #endif |
| 461 | r.m_p->is_nil = lua_isnil(g_lua_state, -1); |
| 462 | r.m_p->is_string = (lua_isstring(g_lua_state, -1) != 0); |
| 463 | r.m_p->is_table = lua_istable(g_lua_state, -1); |
| 464 | r.m_p->is_userdata = (lua_isuserdata(g_lua_state, -1) != 0); |
| 465 | |
| 466 | if (r.m_p->is_function) |
| 467 | { |
| 468 | r.m_p->val_function.LoadFromStack(); |
| 469 | } |
| 470 | |
| 471 | lua_pop(g_lua_state, 1); |
| 472 | |
| 473 | if (r.m_p->is_table) |
| 474 | { |
| 475 | lua_pushnil(g_lua_state); /* first key */ |
| 476 | |
| 477 | // script_dbg_dump_stack(String::FromPrintf("is_table")); |
| 478 |
nothing calls this directly
no test coverage detected