以下引用灯笼菜刀王于2008-8-30 22:41:19的发言:
- -....今年 “最鸡肋脚本奖”应该可以发给楼主了.....
在游戏里要显示对话框直接用显示文章就可以了- -,,,,
class String
CP_ACP = 0
CP_UTF8 = 65001
def u2s
m2w = Win32API.new("kernel32", "MultiByteToWideChar", "ilpipi", "i")
w2m = Win32API.new("kernel32", "WideCharToMultiByte", "ilpipipp", "i")
len = m2w.call(CP_UTF8, 0, self, -1, nil, 0)
buf = "\0" * (len*2)
m2w.call(CP_UTF8, 0, self, -1, buf, buf.size/2)
len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
ret = "\0" * len
w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
return ret
end
def u2s!
self[0, length] = u2s
end
end
module Debug
REPLACE = true
AllocConsole = Win32API.new("kernel32", "AllocConsole", "v", "i")
GetStdHandle = Win32API.new("kernel32", "GetStdHandle", "l", "l")
WriteConsole = Win32API.new("kernel32", "WriteConsole", "lplpp", "i")
FreeConsole = Win32API.new("kernel32", "FreeConsole", "v", "i")
module_function
def init
AllocConsole.call
@h = GetStdHandle.call -11
end
def free
FreeConsole.call
@h = nil
end
def validcheck
raise "必须先调用Debug.init进行初始化!" if @h.nil?
end
def print(*args)
validcheck; str = ""
args.each{|obj| str += obj.is_a?(String) ? obj : obj.inspect}; str.u2s!
WriteConsole.call @h, str, str.length, nil, nil
end
def println
validcheck; WriteConsole.call @h, "\n", 1, nil, nil
end
def p(*args)
validcheck
str = ""; args.each{|obj| str += obj.inspect + "\n"}; str.u2s!
WriteConsole.call @h, str, str.length, nil, nil
end
class << self
private :validcheck
alias puts print
end
if REPLACE
self.init if @h.nil?
end
end
module Kernel
if Debug::REPLACE
def print(*args)
Debug.print *args
end
def p(*args)
Debug.p *args
end
end
end
Debug.print "debug test | 调试 测试", 3.1415, Bitmap.new(3,3)
Debug.println
Debug.p 123456789
Debug.puts Sprite
Debug.println
Debug.p "debug test | 调试 测试", 3.1415, Bitmap.new(3,3)
p "replace p"
print "replace print"
while true
Graphics.update
Input.update
break if Input.trigger?(13)
end
Debug.free
exit
以下引用灼眼的夏娜于2008-8-31 9:03:47的发言:
class String
CP_ACP = 0
CP_UTF8 = 65001
def u2s
m2w = Win32API.new("kernel32", "MultiByteToWideChar", "ilpipi", "i")
w2m = Win32API.new("kernel32", "WideCharToMultiByte", "ilpipipp", "i")
len = m2w.call(CP_UTF8, 0, self, -1, nil, 0)
buf = "\0" * (len*2)
m2w.call(CP_UTF8, 0, self, -1, buf, buf.size/2)
len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
ret = "\0" * len
w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
return ret
end
def u2s!
self[0, length] = u2s
end
end
module Debug
REPLACE = true
AllocConsole = Win32API.new("kernel32", "AllocConsole", "v", "i")
GetStdHandle = Win32API.new("kernel32", "GetStdHandle", "l", "l")
WriteConsole = Win32API.new("kernel32", "WriteConsole", "lplpp", "i")
FreeConsole = Win32API.new("kernel32", "FreeConsole", "v", "i")
module_function
def init
AllocConsole.call
@h = GetStdHandle.call -11
end
def free
FreeConsole.call
@h = nil
end
def validcheck
raise "必须先调用Debug.init进行初始化!" if @h.nil?
end
def print(*args)
validcheck; str = ""
args.each{|obj| str += obj.is_a?(String) ? obj : obj.inspect}; str.u2s!
WriteConsole.call @h, str, str.length, nil, nil
end
def println
validcheck; WriteConsole.call @h, "\n", 1, nil, nil
end
def p(*args)
validcheck
str = ""; args.each{|obj| str += obj.inspect + "\n"}; str.u2s!
WriteConsole.call @h, str, str.length, nil, nil
end
class << self
private :validcheck
alias puts print
end
if REPLACE
self.init if @h.nil?
end
end
module Kernel
if Debug::REPLACE
def print(*args)
Debug.print *args
end
def p(*args)
Debug.p *args
end
end
end
Debug.print "debug test | 调试 测试", 3.1415, Bitmap.new(3,3)
Debug.println
Debug.p 123456789
Debug.puts Sprite
Debug.println
Debug.p "debug test | 调试 测试", 3.1415, Bitmap.new(3,3)
p "replace p"
print "replace print"
while true
Graphics.update
Input.update
break if Input.trigger?(13)
end
Debug.free
exit
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |