コード例 #1
0
ファイル: ApiVM.cs プロジェクト: shihansha/luaLearn
    public void LoadProto(int idx)
    {
        var subProto = LuaStack.Closure.Proto.Protos[idx];
        var closure  = new LuaClosure(subProto);

        LuaStack.Push(closure);
        for (int i = 0; i < subProto.UpValues.Length; i++)
        {
            var uvInfo = subProto.UpValues[i];
            int uvIdx  = uvInfo.Idx;
            if (uvInfo.InStack == 1)
            {
                if (LuaStack.Openuvs == null)
                {
                    LuaStack.Openuvs = new Dictionary <int, LuaUpValue>();
                }
                if (LuaStack.Openuvs.TryGetValue(uvIdx, out LuaUpValue openuv))
                {
                    closure.Upvals[i] = openuv;
                }
                else
                {
                    closure.Upvals[i]       = LuaUpValue.CreateOpen(LuaStack, uvIdx);
                    LuaStack.Openuvs[uvIdx] = closure.Upvals[i];
                }
            }
            else
            {
                closure.Upvals[i] = LuaStack.Closure.Upvals[uvIdx];
            }
        }
    }
コード例 #2
0
ファイル: ApiPush.cs プロジェクト: shihansha/luaLearn
    public void PushCSharpClosure(CSharpFunction f, int n)
    {
        var closure = new LuaClosure(f, n);

        for (int i = n - 1; i >= 0; i--)
        {
            var val = LuaStack.Pop();
            closure.Upvals[i] = LuaUpValue.CreateClosed(val);
        }
        LuaStack.Push(closure);
    }
コード例 #3
0
    public ErrState Load(byte[] chunk, string chunkName, string mode)
    {
        var proto = Prototype.Undump(chunk);
        var c     = new LuaClosure(proto);

        LuaStack.Push(c);
        if (proto.UpValues != null && proto.UpValues.Length > 0)
        {
            var env = Registry.Get(Consts.LUA_RIDX_GLOBALS);
            c.Upvals[0] = LuaUpValue.CreateClosed(env);
        }
        return(ErrState.Ok);
    }