MCPcopy Create free account
hub / github.com/Tencent/xLua / CreateEnumerablePairs

Method CreateEnumerablePairs

Assets/XLua/Src/ObjectTranslator.cs:623–653  ·  view source on GitHub ↗
(RealStatePtr L)

Source from the content-addressed store, hash-verified

621 int enumerable_pairs_func = -1;
622
623 internal void CreateEnumerablePairs(RealStatePtr L)
624 {
625 LuaFunction func = luaEnv.DoString(@"
626 return function(obj)
627 local isKeyValuePair
628 local function lua_iter(cs_iter, k)
629 if cs_iter:MoveNext() then
630 local current = cs_iter.Current
631 if isKeyValuePair == nil then
632 if type(current) == 'userdata' then
633 local t = current:GetType()
634 isKeyValuePair = t.Name == 'KeyValuePair`2' and t.Namespace == 'System.Collections.Generic'
635 else
636 isKeyValuePair = false
637 end
638 --print(current, isKeyValuePair)
639 end
640 if isKeyValuePair then
641 return current.Key, current.Value
642 else
643 return k + 1, current
644 end
645 end
646 end
647 return lua_iter, obj:GetEnumerator(), -1
648 end
649 ")[0] as LuaFunction;
650 func.push(L);
651 enumerable_pairs_func = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
652 func.Dispose();
653 }
654
655 public void OpenLib(RealStatePtr L)
656 {

Callers 1

LuaEnv.csFile · 0.80

Calls 3

pushMethod · 0.80
luaL_refMethod · 0.80
DisposeMethod · 0.80

Tested by

no test coverage detected