赞 | 12 |
VIP | 107 |
好人卡 | 6 |
积分 | 4 |
经验 | 31122 |
最后登录 | 2024-6-29 |
在线时间 | 1606 小时 |
Lv2.观梦者 傻♂逼
- 梦石
- 0
- 星屑
- 374
- 在线时间
- 1606 小时
- 注册时间
- 2007-3-13
- 帖子
- 6562
|
晴兰 发表于 2011-12-21 23:16
哦哦 原来如此 那也行 这个可以当C函数指针用
不过直接用RGSS3的Ruby写回调还是麻烦T_T ...
- module DL
- SEM = Mutex.new
- def set_callback_internal(proc_entry, addr_entry, argc, ty, abi = nil, &cbp)
- if( argc < 0 )
- raise(ArgumentError, "arity should not be less than 0.")
- end
- addr = nil
- SEM.synchronize{
- ary = proc_entry[ty]
- (0...MAX_CALLBACK).each{|n|
- idx = (n * DLSTACK_SIZE) + argc
- if( ary[idx].nil? )
- ary[idx] = cbp
- addr = addr_entry[ty][idx]
- break
- end
- }
- }
- addr
- end
- def set_cdecl_callback(ty, argc, &cbp)
- set_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, argc, ty, &cbp)
- end
- def set_stdcall_callback(ty, argc, &cbp)
- set_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, argc, ty, &cbp)
- end
- def remove_callback_internal(proc_entry, addr_entry, addr, ctype = nil)
- index = nil
- if( ctype )
- addr_entry[ctype].each_with_index{|xaddr, idx|
- if( xaddr == addr )
- index = idx
- end
- }
- else
- addr_entry.each{|ty,entry|
- entry.each_with_index{|xaddr, idx|
- if( xaddr == addr )
- index = idx
- end
- }
- }
- if( index and proc_entry[ctype][index] )
- proc_entry[ctype][index] = nil
- return true
- else
- return false
- end
- end
- end
- def remove_cdecl_callback(addr, ctype = nil)
- remove_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, addr, ctype)
- end
- def remove_stdcall_callback(addr, ctype = nil)
- remove_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, addr, ctype)
- end
- alias set_callback set_cdecl_callback
- alias remove_callback remove_cdecl_callback
- end
复制代码 没测试过 |
|