상속: LuaObject
예제 #1
0
        public void openSluaLib()
        {
            LuaArray.init(L);
            LuaVarObject.init(L);

            LuaDLL.lua_newtable(L);
            LuaDLL.lua_setglobal(L, DelgateTable);

#if !SLUA_STANDALONE
            LuaTimer.reg(L);
            LuaCoroutine.reg(L, lgo);
#endif
            Lua_SLua_ByteArray.reg(L);
            Helper.reg(L);

            openedSluaLib = true;
        }
예제 #2
0
        public static void init(IntPtr l)
        {
            string newindexfun = @"

local getmetatable=getmetatable
local rawget=rawget
local error=error
local type=type
local function newindex(ud,k,v)
    local t=getmetatable(ud)
    repeat
        local h=rawget(t,k)
        if h then
			if h[2] then
				h[2](ud,v)
	            return
			else
				error('property '..k..' is read only')
			end
        end
        t=rawget(t,'__parent')
    until t==nil
    error('can not find '..k)
end

return newindex
";

            string   indexfun = @"
local type=type
local error=error
local rawget=rawget
local getmetatable=getmetatable
local function index(ud,k)
    local t=getmetatable(ud)
    repeat
        local fun=rawget(t,k)
        local tp=type(fun)	
        if tp=='function' then 
            return fun 
        elseif tp=='table' then
			local f=fun[1]
			if f then
				return f(ud)
			else
				error('property '..k..' is write only')
			end
        end
        t = rawget(t,'__parent')
    until t==nil
    error('Can not find '..k)
end

return index
";
            LuaState L        = LuaState.get(l);

            newindex_func = (LuaFunction)L.doString(newindexfun);
            index_func    = (LuaFunction)L.doString(indexfun);

            // object method
            LuaDLL.lua_createtable(l, 0, 4);
            addMember(l, ToString);
            addMember(l, GetHashCode);
            addMember(l, Equals);
            addMember(l, GetType);
            LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, "__luabaseobject");

            LuaArray.init(l);
            LuaVarObject.init(l);

            LuaDLL.lua_newtable(l);
            LuaDLL.lua_setglobal(l, DelgateTable);


            setupPushVar();
        }
예제 #3
0
        public static void init(IntPtr l)
        {
            string newindexfun = @"

local getmetatable=getmetatable
local rawget=rawget
local error=error
local type=type
local function newindex(ud,k,v)
    local t=getmetatable(ud)
    repeat
        local h=rawget(t,k)
        if h then
			if h[2] then
				h[2](ud,v)
	            return
			else
				error('property '..k..' is read only')
			end
        end
        t=rawget(t,'__parent')
    until t==nil
    error('can not find '..k)
end

return newindex
";

            string indexfun = @"
local type=type
local error=error
local rawget=rawget
local sub=string.sub
local function index(ud,k)
    local t=getmetatable(ud)
    repeat
        local fun=rawget(t,k)
        local tp=type(fun)	
        if tp=='function' then 
            return fun 
        elseif tp=='table' then
			if fun[1] then
				return fun[1](ud)
			else
				error('property '..k..' is write only')
			end
        end
        t = rawget(t,'__parent')
    until t==nil
    error('Can not find '..k)
end

return index
";

            if (LuaDLL.luaL_dostring(l, newindexfun) != 0)
            {
                throwLuaError(l);
                return;
            }
            newindex_ref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX);

            if (LuaDLL.luaL_dostring(l, indexfun) != 0)
            {
                throwLuaError(l);
                return;
            }
            index_ref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX);

            // object method

            LuaDLL.lua_newtable(l);
            addMember(l, ToString);
            addMember(l, GetHashCode);
            addMember(l, Equals);
            LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, "__luabaseobject");

            LuaVarObject.init(l);

            LuaDLL.lua_newtable(l);
            LuaDLL.lua_setglobal(l, DelgateTable);


            setupPushVar();
        }
예제 #4
0
        public static void init(IntPtr l)
        {
            string newindexfun = @"

local getmetatable=getmetatable
local rawget=rawget
local error=error
local type=type
local function newindex(ud,k,v)
    local t=getmetatable(ud)
    repeat
        local h=rawget(t,k)
        if h then
            h[2](ud,v)
            return
        end
        t=rawget(t,'__parent')
    until t==nil
    error('can not find '..k)
end

return newindex
";

            string indexfun = @"
local type=type
local error=error
local rawget=rawget
local sub=string.sub
local function index(ud,k)
    local t=getmetatable(ud)
    repeat
        local fun=rawget(t,k)
        local tp=type(fun)
        if tp=='function' then 
            return fun 
        elseif tp=='table' then
            return fun[1](ud)
        end
        t = rawget(t,'__parent')
    until t==nil
    error('Can not find '..k)
end

return index
";

            if (LuaDLL.luaL_dostring(l, newindexfun) != 0)
            {
                throwLuaError(l);
                return;
            }
            newindex_ref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX);

            if (LuaDLL.luaL_dostring(l, indexfun) != 0)
            {
                throwLuaError(l);
                return;
            }
            index_ref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX);

            LuaVarObject.init(l);
            //LuaValueType.init(l);
        }
예제 #5
0
        public static void Init(IntPtr ptr)
        {
            string newindexfun = @"

local getmetatable=getmetatable
local rawget=rawget
local error=error
local type=type
local function newindex(ud,k,v)
    local t=getmetatable(ud)
    repeat
        local h=rawget(t,k)
        if h then
            if h[2] then
                h[2](ud,v)
                return
            else
                error('property '..k..' is read only')
            end
        end
        t=rawget(t,'__parent')
    until t==nil
    error('can not find '..k)
end

return newindex
";

            string   indexfun = @"
local type=type
local error=error
local rawget=rawget
local getmetatable=getmetatable
local function index(ud,k)
    local t=getmetatable(ud)
    repeat
        local fun=rawget(t,k)
        local tp=type(fun)
        if tp=='function' then
            return fun
        elseif tp=='table' then
            local f=fun[1]
            if f then
                return f(ud)
            else
                error('property '..k..' isthis.Write only')
            end
        end
        t = rawget(t,'__parent')
    until t==nil
    error('Can not find '..k)
end

return index
";
            LuaState state    = LuaState.Get(ptr);

            newIndexFunction = (LuaFunction)state.DoString(newindexfun);
            indexFunction    = (LuaFunction)state.DoString(indexfun);

            // object method
            LuaNativeMethods.lua_createtable(ptr, 0, 4);
            AddMember(ptr, ToString);
            AddMember(ptr, GetHashCode);
            AddMember(ptr, Equals);
            AddMember(ptr, GetType);
            LuaNativeMethods.lua_setfield(ptr, LuaIndexes.LUARegistryIndex, "__luabaseobject");

            LuaArray.Init(ptr);
            LuaVarObject.Init(ptr);

            LuaNativeMethods.lua_newtable(ptr);
            LuaNativeMethods.lua_setglobal(ptr, DelgateTable);
        }