def install_readline(hook):
'''Set up things for the interpreter to call
our function like GNU readline.'''
global readline_hook, readline_ref
# save the hook so the wrapper can call it
readline_hook = hook
# get the address of PyOS_ReadlineFunctionPointer so we can update it
PyOS_RFP = c_void_p.from_address(Console.GetProcAddress(sys.dllhandle,
"PyOS_ReadlineFunctionPointer".encode('ascii')))
# save a reference to the generated C-callable so it doesn't go away
if sys.version < '2.3':
readline_ref = HOOKFUNC22(hook_wrapper)
else:
readline_ref = HOOKFUNC23(hook_wrapper_23)
# get the address of the function
func_start = c_void_p.from_address(addressof(readline_ref)).value
# write the function address into PyOS_ReadlineFunctionPointer
PyOS_RFP.value = func_start
评论列表
文章目录