예제 #1
0
        private void F_Load( object ud )
        {
            var param = (LoadParameter)ud;

            LuaProto proto;
            var c = param.LoadInfo.PeekByte();
            if( c == LuaConf.LUA_SIGNATURE[0] )
            {
                CheckMode( param.Mode, "binary" );
                proto = Undump.LoadBinary( this, param.LoadInfo, param.Name );
            }
            else
            {
                CheckMode( param.Mode, "text" );
                proto = Parser.Parse( this, param.LoadInfo, param.Name );
            }

            var cl = new LuaLClosure( proto );
            Utl.Assert( cl.Upvals.Count == cl.Proto.Upvalues.Count );

            // initialize upvalues
            for( int i=0; i<proto.Upvalues.Count; ++i )
            {
                cl.Upvals[i] = new LuaUpvalue();
            }

            Top.Value = cl;
            IncrTop();
        }
예제 #2
0
파일: VM.cs 프로젝트: matthewyang/UniLua
        private void V_PushClosure( LuaProto p, List<LuaUpvalue> encup, StkId stackBase, StkId ra )
        {
            LuaLClosure ncl = new LuaLClosure( p );
            ra.Value = ncl;
            for( int i=0; i<p.Upvalues.Count; ++i )
            {
                // Debug.Log( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ V_PushClosure i:" + i );
                // Debug.Log( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ V_PushClosure InStack:" + p.Upvalues[i].InStack );
                // Debug.Log( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ V_PushClosure Index:" + p.Upvalues[i].Index );

                if( p.Upvalues[i].InStack ) // upvalue refers to local variable
                    ncl.Upvals[i] = F_FindUpval( stackBase + p.Upvalues[i].Index );
                else	// get upvalue from enclosing function
                    ncl.Upvals[i] = encup[ p.Upvalues[i].Index ];
            }
        }