예제 #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);
    }
예제 #2
0
 public static int Trace(Lua.lua_State lua)
 {
     Lua.CharPtr cp = Lua.lua_tostring(lua, 1);
     using (var sw = File.AppendText("log.txt"))
         sw.Write(cp.chars);
     return(0);
 }
예제 #3
0
파일: luna.cs 프로젝트: xubingyue/lwf
 public static void dostring(Lua.lua_State L, Lua.CharPtr luacode)
 {
     // Lua.luaL_dostring followed by pcall error checking
     if (Lua.luaL_loadstring(L, luacode) != 0 || Lua.lua_pcall(L, 0, Lua.LUA_MULTRET, 0) != 0)
     {
         print("Lua error: stack :");
         printStack(L, false);
     }
 }
예제 #4
0
파일: luna.cs 프로젝트: ufosky/lwf
 public static void dostring(Lua.lua_State L, Lua.CharPtr luacode)
 {
     // Lua.luaL_dostring followed by pcall error checking
     if (Lua.luaL_dostring(L, luacode) == 1)
     {
         print("Lua error: stack :");
         printStack(L, false);
     }
 }
예제 #5
0
    public static Stream FOpen(Lua.CharPtr cFilename, Lua.CharPtr cMode)
    {
        string filename = "/" + cFilename.ToString();

        filename = filename.Replace("\\", "/").Replace("/./", "/");
        filename = filename.Substring(1);         // remove the leading slash again

        //bool read = true;
        bool write      = false;
        bool truncate   = false;
        bool startAtEnd = false;

        if (cMode.chars.Length != 0)
        {
            int pos = 0;
            switch (cMode.chars[pos])
            {
            case 'r':
                break;

            case 'w':
                //read = false;
                write    = true;
                truncate = true;
                break;

            case 'a':
                //read = false;
                write      = true;
                startAtEnd = true;
                break;

            default:
                throw new ArgumentException(string.Format("Bad mode character '{0}' at position {1} in mode '{2}'", cMode.chars[pos], pos, cMode.ToString()));
            }
            ++pos;

            if (cMode.chars[pos] == '+')
            {
                //read = true;
                write = true;
                ++pos;
            }

            if (cMode.chars[pos] == 'b')
            {
                // ignore
                ++pos;
            }

            if (cMode.chars[pos] != '\0')
            {
                throw new ArgumentException(string.Format("Bad mode character '{0}' at position {1} in mode '{2}'", cMode.chars[pos], pos, cMode.ToString()));
            }
        }

        // Try to populate from Unity Resources, but don't bother if we're truncating
        if (!truncate && !_fileSystem.ContainsKey(filename))
        {
            PopulateFromResource(filename);
        }

        // If we're not writing, we just use a read-only MemoryStream to access the data, allowing simultaneous reads
        if (!write)
        {
            if (!_fileSystem.ContainsKey(filename))
            {
                throw new FileNotFoundException(string.Format("File not found - {0}", filename));
            }

            return(new MemoryStream(_fileSystem[filename], false));
        }

        // Since we're writing we need to use a fancy derivative of MemoryStream that knows how to bake the data into
        // the filesystem when it is disposed
        var stream = new FileMemoryStream(filename, truncate, startAtEnd);

        return(stream);
    }
예제 #6
0
 public RegType(Lua.CharPtr name, Lua.lua_CFunction func)
 {
     this.name  = name;
     this.mfunc = func;
 }
예제 #7
0
 public static void set(Lua.lua_State L, int table_index, Lua.CharPtr key)
 {
     Lua.lua_pushstring(L, key);
     Lua.lua_insert(L, -2);          // swap value and key
     Lua.lua_settable(L, table_index);
 }