| 783 | // class init |
| 784 | template<typename T> |
| 785 | void class_add(lua_State* L, const char* name) |
| 786 | { |
| 787 | // 通过类名设置类table |
| 788 | // 如果该类没有注册,在lua中是获取不到类信息的 |
| 789 | class_name<T>::name(name); |
| 790 | |
| 791 | lua_newtable(L); |
| 792 | |
| 793 | lua_pushstring(L, "__name"); |
| 794 | lua_pushstring(L, name); |
| 795 | lua_rawset(L, -3); |
| 796 | |
| 797 | lua_pushstring(L, "__index"); |
| 798 | lua_pushcclosure(L, meta_get, 0); |
| 799 | lua_rawset(L, -3); |
| 800 | |
| 801 | lua_pushstring(L, "__newindex"); |
| 802 | lua_pushcclosure(L, meta_set, 0); |
| 803 | lua_rawset(L, -3); |
| 804 | |
| 805 | lua_pushstring(L, "__gc"); |
| 806 | lua_pushcclosure(L, destroyer<T>, 0); |
| 807 | lua_rawset(L, -3); |
| 808 | |
| 809 | lua_setglobal(L, name); |
| 810 | } |
| 811 | |
| 812 | // Tinker Class Inheritence |
| 813 | template<typename T, typename P> |
nothing calls this directly
no test coverage detected