| 660 | } |
| 661 | |
| 662 | uint32_t SetGlobal(lua_State* L, const char* name) |
| 663 | { |
| 664 | size_t name_length = strlen(name); |
| 665 | uint32_t name_hash = dmHashBuffer32(name, name_length); |
| 666 | // [-1] instance |
| 667 | |
| 668 | lua_pushlstring(L, name, name_length); |
| 669 | // [-1] name |
| 670 | // [-2] instance |
| 671 | |
| 672 | lua_pushvalue(L, -2); |
| 673 | // [-1] instance |
| 674 | // [-2] name |
| 675 | // [-3] instance |
| 676 | |
| 677 | lua_settable(L, LUA_GLOBALSINDEX); |
| 678 | // [-1] instance |
| 679 | |
| 680 | lua_pushinteger(L, (lua_Integer)name_hash); |
| 681 | // [-1] name_hash |
| 682 | // [-2] instance |
| 683 | |
| 684 | lua_insert(L, -2); |
| 685 | // [-1] instance |
| 686 | // [-2] name_hash |
| 687 | |
| 688 | lua_settable(L, LUA_GLOBALSINDEX); |
| 689 | |
| 690 | return name_hash; |
| 691 | } |
| 692 | |
| 693 | void GetGlobal(lua_State*L, uint32_t name_hash) |
| 694 | { |
no test coverage detected