Luna.userdataType.ToBytes C# (CSharp) Method

ToBytes() public method

public ToBytes ( byte dst ) : void
dst byte
return void
        public void ToBytes(byte[] dst)
        {
            BitConverter.GetBytes(typeId).CopyTo(dst, 0);
            BitConverter.GetBytes(objectId).CopyTo(dst, 4);
            BitConverter.GetBytes(gc).CopyTo(dst, 8);
            BitConverter.GetBytes(has_env).CopyTo(dst, 9);
        }

Usage Example

コード例 #1
0
    // use lunaStack::push if possible.
    public static void push(Lua.lua_State L, LWF.Point obj, bool gc, Lua.CharPtr metatable = null)
    {
        int objectId = -1;

        if (!objectIdentifiers[L].TryGetValue(obj, out objectId))
        {
            objectId = idOffset++;
            objectIdentifiers[L].Add(obj, objectId);
            objects[L].Add(objectId, obj);
        }

        if (metatable == null)
        {
            metatable = LunaTraits_LWF_Point.className;
        }
        Lua.lua_pushstring(L, "__luna");
        Lua.lua_gettable(L, Lua.LUA_GLOBALSINDEX);
        int __luna = Lua.lua_gettop(L);

        Luna.userdataType ud = new Luna.userdataType(
            objectId: objectId,  // store object in userdata
            gc: gc,              // collect garbage
            has_env: false,      // does this userdata has a table attached to it?
            typeId: LunaTraits_LWF_Point.uniqueID
            );

        ud.ToBytes((byte[])Lua.lua_newuserdata(L, Luna.userdataType.Size));

        Lua.lua_pushstring(L, metatable);
        Lua.lua_gettable(L, __luna);
        Lua.lua_setmetatable(L, -2);
        //Luna.printStack(L);
        Lua.lua_insert(L, -2);          // swap __luna and userdata
        Lua.lua_pop(L, 1);
    }
All Usage Examples Of Luna.userdataType::ToBytes
Luna.userdataType