赞 | 1 |
VIP | 1647 |
好人卡 | 10 |
积分 | 1 |
经验 | 363065 |
最后登录 | 2016-8-26 |
在线时间 | 1707 小时 |
Lv1.梦旅人 炎发灼眼的讨伐者
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 1707 小时
- 注册时间
- 2007-8-4
- 帖子
- 904
|
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 |
|