예제 #1
0
 public LuaArgs unmount(LuaArgs args)
 {
     try
     {
         if (args.IsString(0))
         {
             var path = new FilePath(args.GetString(0));
             m_fileSystem.Unmount(path);
         }
         else
         {
             var mount = args.GetObject <LuaMount>(0);
             m_fileSystem.Unmount(mount);
         }
         return(LuaArgs.Empty);
     }
     catch (IOException e)
     {
         throw new LuaError(e.Message);
     }
 }
예제 #2
0
        public LuaArgs loadTGA(LuaArgs args)
        {
            try
            {
                // Load image
                Image   image;
                Palette palette;
                if (args.IsString(0))
                {
                    // Load from a string
                    var bytes = args.GetByteString(0);
                    using (var stream = new MemoryStream(bytes))
                    {
                        image = TGAImage.Decode(stream, m_computer.Memory, out palette);
                    }
                }
                else
                {
                    // Load from a stream
                    var file = args.GetObject <LuaFile>(0);
                    CheckFileMode(file, "tga", LuaFileOpenMode.Read, LuaFileContentType.Binary);
                    image = TGAImage.Decode(file.InnerStream, m_computer.Memory, out palette);
                }

                // Return image
                return(new LuaArgs(
                           new LuaImage(image, m_computer.Memory),
                           new LuaPalette(palette, m_computer.Memory)
                           ));
            }
            catch (OutOfMemoryException)
            {
                throw new LuaError("not enough memory");
            }
            catch (IOException e)
            {
                throw new LuaError(e.Message);
            }
        }