, Cygwin. Windows , Ruby Gem, win32-pipe, .
, , Ruby Gems RGSS script; , win32-pipe, RGSS. , , .
script "" :
module PipeLogger
PIPE_NAME = "RGSSPipe"
PIPE_DEFAULT_MODE = 0
PIPE_ACCESS_DUPLEX = 0x00000003
PIPE_UNLIMITED_INSTANCES = 255
PIPE_BUFFER_SIZE = 1024
PIPE_TIMEOUT = 5000
INVALID_HANDLE_VALUE = 0xFFFFFFFF
def self.make_APIs
$CreateNamedPipe = Win32API.new('kernel32', 'CreateNamedPipe', 'PLLLLLLL', 'L')
$FlushFileBuffers = Win32API.new('kernel32', 'FlushFileBuffers', 'L', 'B')
$DisconnectNamedPipe = Win32API.new('kernel32', 'DisconnectNamedPipe', 'L', 'B')
$WriteFile = Win32API.new('kernel32', 'WriteFile', 'LPLPP', 'B')
$CloseHandle = Win32API.new('kernel32', 'CloseHandle', 'L', 'B')
end
def self.setup_pipe
make_APIs
@@name = "\\\\.\\pipe\\" + PIPE_NAME
@@pipe_mode = PIPE_DEFAULT_MODE
@@open_mode = PIPE_ACCESS_DUPLEX
@@pipe = nil
@@buffer = 0.chr * PIPE_BUFFER_SIZE
@@size = 0
@@bytes = [0].pack('L')
@@pipe = $CreateNamedPipe.call(
@@name,
@@open_mode,
@@pipe_mode,
PIPE_UNLIMITED_INSTANCES,
PIPE_BUFFER_SIZE,
PIPE_BUFFER_SIZE,
PIPE_TIMEOUT,
0
)
if @@pipe == INVALID_HANDLE_VALUE
print "WARNING -- Unable to create named pipe: " + PIPE_NAME
@@pipe = nil
else
print "Please launch the RGSSMonitor.rb script"
end
end
def self.write_to_pipe(msg)
if @@pipe
@@buffer = msg
@@size = msg.size
$WriteFile.call(@@pipe, @@buffer, @@buffer.size, @@bytes, 0)
end
end
def self.close_pipe
if @@pipe
@@buffer = "!!GAMEOVER!!"
@@size = @@buffer.size
$WriteFile.call(@@pipe, @@buffer, @@buffer.size, @@bytes, 0)
$FlushFileBuffers.call(@@pipe)
$DisconnectNamedPipe.call(@@pipe)
$CloseHandle.call(@@pipe)
@@pipe = nil
end
end
end
, PipeLogger::setup_pipe, ; PipeLogger::close_pipe . ( "Main" ensure close_pipe.) PipeLogger::write_to_pipe("msg") script string "msg" .
RPG Maker XP; RPG Maker VX .
- . , - Ruby, Ruby Gem win32-pipe script:
require 'rubygems'
require 'win32/pipe'
include Win32
PIPE_NAME = "RGSSPipe"
Thread.new { loop { sleep 0.01 } }
pipe = Pipe::Client.new(PIPE_NAME)
continue = true
while continue
msg = pipe.read.to_s
puts msg
continue = false if msg.chomp == "!!GAMEOVER!!"
end
Ruby 1.8.7 Windows win32-pipe , (. ). "RGSSMonitor.rb" ruby RGSSMonitor.rb.
:
- RGSS, , ; , . , .
- , , , , (,
RGSSMonitor.rb). Windows ( 1K), ( " ", ). , RPGXP Ruby script, 10 . ( , RPGVX - .)