Use define_method instead of module_eval.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ttate 2005-02-07 23:08:26 +00:00
parent c47ca1f02f
commit 3977dbc576
2 changed files with 13 additions and 13 deletions

View File

@ -118,12 +118,12 @@ module DL
f = import_function(symname, ctype, argtype, opt[:call_type]) f = import_function(symname, ctype, argtype, opt[:call_type])
name = symname.gsub(/@.+/,'') name = symname.gsub(/@.+/,'')
@func_map[name] = f @func_map[name] = f
#define_method(name){|*args,&block| f.call(*args,&block)} define_method(name){|*args,&block| f.call(*args,&block)}
module_eval(<<-EOS) #module_eval(<<-EOS)
def #{name}(*args, &block) # def #{name}(*args, &block)
@func_map['#{name}'].call(*args,&block) # @func_map['#{name}'].call(*args,&block)
end # end
EOS #EOS
module_function(name) module_function(name)
f f
end end
@ -142,12 +142,12 @@ module DL
raise(RuntimeError, "unknown callback type: #{h[:callback_type]}") raise(RuntimeError, "unknown callback type: #{h[:callback_type]}")
end end
@func_map[name] = f @func_map[name] = f
#define_method(name){|*args,&block| f.call(*args,&block)} define_method(name){|*args,&block| f.call(*args,&block)}
module_eval(<<-EOS) #module_eval(<<-EOS)
def #{name}(*args,&block) # def #{name}(*args,&block)
@func_map['#{name}'].call(*args,&block) # @func_map['#{name}'].call(*args,&block)
end # end
EOS #EOS
module_function(name) module_function(name)
f f
end end

View File

@ -54,7 +54,7 @@ module DL
def test_io() def test_io()
io_in,io_out = IO.pipe() io_in,io_out = IO.pipe()
LIBC.fprintf(DL::CPtr[io_out], "hello") LIBC.fprintf(io_out, "hello")
io_out.flush() io_out.flush()
io_out.close() io_out.close()
str = io_in.read() str = io_in.read()