MCPcopy Create free account
hub / github.com/SOUI2/soui / meta_get

Method meta_get

components/ScriptModule-LUA/lua_tinker/lua_tinker.cpp:650–697  ·  view source on GitHub ↗

---------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

648
649/*---------------------------------------------------------------------------*/
650int lua_tinker::meta_get(lua_State *L)
651{
652 // 传入表 和 索引参数
653 // stack: 1.类(userdata) 2.变量(string)
654 lua_getmetatable(L,1);
655 // stack: 1.类(userdata) 2.变量(string) 3.meta(table)
656 lua_pushvalue(L,2);
657 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.变量(string)
658 lua_rawget(L,-2);
659 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.meta[变量]value值(userdata)
660
661 // 如果存在userdata 存在该变量
662 if(lua_isuserdata(L,-1))
663 {
664 user2type<var_base*>::invoke(L,-1)->get(L);
665 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.meta[变量]value值(userdata) 5.实际值
666 lua_remove(L, -2);
667 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.实际值
668 }
669 else if(lua_isnil(L,-1))
670 {
671 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.nil
672 lua_remove(L,-1);
673 // stack: 1.类(userdata) 2.变量(string) 3.meta(table)
674 invoke_parent(L);
675 // fix bug by fergus
676 // 调用父类也需调用get
677 if(lua_isuserdata(L,-1))
678 {
679 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.父类中的变量(userdata)
680 user2type<var_base*>::invoke(L,-1)->get(L);
681 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.父类中的变量(userdata) 5.实际值
682 lua_remove(L, -2);
683 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.实际值
684 }
685 else if(lua_isnil(L,-1))
686 {
687 // stack: 1.类(userdata) 2.变量(string) 3.meta(table) 4.nil
688 lua_pushfstring(L, "can't find '%s' class variable. (forgot registering class variable ?)", lua_tostring(L, 2));
689 lua_error(L);
690 }
691 }
692
693 lua_remove(L,-2);
694 // stack: 1.类(userdata) 2.变量(string) 3.实际值
695
696 return 1;
697}
698
699/*---------------------------------------------------------------------------*/
700int lua_tinker::meta_set(lua_State *L)

Callers

nothing calls this directly

Calls 9

lua_getmetatableFunction · 0.85
lua_pushvalueFunction · 0.85
lua_rawgetFunction · 0.85
lua_isuserdataFunction · 0.85
lua_removeFunction · 0.85
invoke_parentFunction · 0.85
lua_pushfstringFunction · 0.85
lua_errorFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected