| 559 | } |
| 560 | |
| 561 | int lua_pushsvt(lua_State* L, CScriptVarsTable* T) |
| 562 | { |
| 563 | SCRIPT_VAR* sv = (SCRIPT_VAR*)lua_newuserdata(L, sizeof(SCRIPT_VAR)); |
| 564 | sv->type = LUA_TTABLE; |
| 565 | sv->size = 4; |
| 566 | sv->T = T; |
| 567 | T->add_ref(); // регистрация выдачи экземпляра в lua |
| 568 | int value_index = lua_gettop(L); |
| 569 | luaL_getmetatable(L, "GMT_SCRIPT_VARS"); |
| 570 | int mt = lua_gettop(L); |
| 571 | if (!lua_istable(L, -1)) |
| 572 | { |
| 573 | lua_pop(L, 1); |
| 574 | luaL_newmetatable(L, "GMT_SCRIPT_VARS"); |
| 575 | register_method(L, "__gc", mt, script_vars_release); |
| 576 | register_method(L, "__len", mt, script_vars_size); |
| 577 | register_method(L, "__call", mt, script_vars_dump); |
| 578 | register_method(L, "__index", mt, script_vars_index); |
| 579 | register_method(L, "__newindex", mt, script_vars_new_index); |
| 580 | lua_pushvalue(L, mt); |
| 581 | lua_setfield(L, mt, "__metatable"); |
| 582 | } |
| 583 | lua_setmetatable(L, value_index); |
| 584 | return 1; |
| 585 | } |
| 586 | |
| 587 | int script_vars_create(lua_State* L) // создание таблицы переменных и опциональное заполнение из второго аргумента |
| 588 | { |
no test coverage detected