本文整理汇总了C++中rb_block_proc函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_block_proc函数的具体用法?C++ rb_block_proc怎么用?C++ rb_block_proc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_block_proc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sig_trap
/*
* call-seq:
* Signal.trap( signal, proc ) => obj
* Signal.trap( signal ) {| | block } => obj
*
* Specifies the handling of signals. The first parameter is a signal
* name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a
* signal number. The characters ``SIG'' may be omitted from the
* signal name. The command or block specifies code to be run when the
* signal is raised. If the command is the string ``IGNORE'' or
* ``SIG_IGN'', the signal will be ignored. If the command is
* ``DEFAULT'' or ``SIG_DFL'', the operating system's default handler
* will be invoked. If the command is ``EXIT'', the script will be
* terminated by the signal. Otherwise, the given command or block
* will be run.
* The special signal name ``EXIT'' or signal number zero will be
* invoked just prior to program termination.
* trap returns the previous handler for the given signal.
*
* Signal.trap(0, proc { puts "Terminating: #{$$}" })
* Signal.trap("CLD") { puts "Child died" }
* fork && Process.wait
*
* produces:
* Terminating: 27461
* Child died
* Terminating: 27460
*/
static VALUE
sig_trap(int argc, VALUE *argv)
{
struct trap_arg arg;
rb_secure(2);
if (argc == 0 || argc > 2) {
rb_raise(rb_eArgError, "wrong number of arguments -- trap(sig, cmd)/trap(sig){...}");
}
arg.sig = argv[0];
if (argc == 1) {
arg.cmd = rb_block_proc();
}
else if (argc == 2) {
arg.cmd = argv[1];
}
if (OBJ_TAINTED(arg.cmd)) {
rb_raise(rb_eSecurityError, "Insecure: tainted signal trap");
}
#ifndef _WIN32
/* disable interrupt */
# ifdef HAVE_SIGPROCMASK
sigfillset(&arg.mask);
sigprocmask(SIG_BLOCK, &arg.mask, &arg.mask);
# else
arg.mask = sigblock(~0);
# endif
return rb_ensure(trap, (VALUE)&arg, trap_ensure, (VALUE)&arg);
#else
return trap(&arg);
#endif
}
开发者ID:RWB01,项目名称:Code-Translator,代码行数:63,代码来源:signal.c
示例2: _appendNormalItem
VALUE _appendNormalItem(int argc,VALUE *argv,VALUE self)
{
VALUE id,text,help,temp;
rb_scan_args(argc, argv, "1*",&id,&temp);
if(rb_obj_is_kind_of(id,rb_cString) && rb_block_given_p()){
rb_scan_args(argc, argv, "11",&text,&help);
wxMenu *m = new wxMenu;
rb_yield(wrap(m));
return wrap(_self->AppendSubMenu(m,wrap<wxString>(text),wrap<wxString>(help)));
}else{
rb_scan_args(argc, argv, "12",&id,&text,&help);
wxWindowID wid = unwrapID(id);
if(!wxIsStockID(wid) && NIL_P(text))
rb_raise(rb_eArgError,"id %d needs an text",wid);
wxMenuItem *item = _self->Append(wid,wrap<wxString>(text),wrap<wxString>(help));
if(rb_block_given_p()){
VALUE proc = rb_block_proc();
#ifdef wxHAS_EVENT_BIND
_self->Bind(wxEVT_COMMAND_MENU_SELECTED,RubyFunctor(proc),item->GetId());
#else
_self->Connect(item->GetId(),wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(RubyFunctor::operator()),NULL,new RubyFunctor(proc));
#endif
}
return wrap(item);
}
}
开发者ID:ileitch,项目名称:rwx,代码行数:28,代码来源:wxMenu.cpp
示例3: rb_gst_index_get_assoc_entry
/*
* Method: get_assoc_entry(id, method, flags, format, value) { ... }
* id: the ID of the index writer.
* method: the lookup method to use (see Gst::Index::LookupMethod).
* flags: flags for the entry (see Gst::Index::AssocFlags).
* format: a Gst::Format object.
* value: the value to find.
*
* Finds the given format/value in the index. If a block is given, it will be
* called as a compare function, passing references to 2 Gst::IndexEntry objects,
* and waiting for a boolean as the return value.
*
* Returns: the entry associated with the value (as a Gst::IndexEntry object), or nil
* if the value is not found.
*/
static VALUE
rb_gst_index_get_assoc_entry (VALUE self, VALUE id, VALUE method, VALUE flags,
VALUE format, VALUE value)
{
GstIndexEntry *index_entry;
if (rb_block_given_p () == Qfalse)
index_entry =
gst_index_get_assoc_entry (RGST_INDEX (self), FIX2INT (id),
RVAL2GENUM (method,
GST_TYPE_INDEX_LOOKUP_METHOD),
RVAL2GFLAGS (flags,
GST_TYPE_ASSOC_FLAGS),
*RGST_FORMAT (format), NUM2ULL (value));
else
index_entry =
gst_index_get_assoc_entry_full (RGST_INDEX (self), FIX2INT (id),
RVAL2GENUM (method,
GST_TYPE_INDEX_LOOKUP_METHOD),
RVAL2GFLAGS (flags,
GST_TYPE_ASSOC_FLAGS),
*RGST_FORMAT (format),
NUM2ULL (value), __compare,
(gpointer) rb_block_proc ());
return index_entry != NULL ? RGST_INDEX_ENTRY_NEW (index_entry)
: Qnil;
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:43,代码来源:rbgstindex.c
示例4: sig_trap
static VALUE
sig_trap(VALUE rcv, SEL sel, int argc, VALUE *argv)
{
struct trap_arg arg;
rb_secure(2);
if (argc == 0 || argc > 2) {
rb_raise(rb_eArgError, "wrong number of arguments -- trap(sig, cmd)/trap(sig){...}");
}
arg.sig = trap_signm(argv[0]);
if (argc == 1) {
arg.cmd = rb_block_proc();
arg.func = sighandler;
}
else {
arg.cmd = argv[1];
arg.func = trap_handler(&arg.cmd, arg.sig);
}
if (OBJ_TAINTED(arg.cmd)) {
rb_raise(rb_eSecurityError, "Insecure: tainted signal trap");
}
return trap(&arg);
}
开发者ID:MSch,项目名称:MacRuby,代码行数:26,代码来源:signal.c
示例5: rb_gst_index_set_resolver
static VALUE
rb_gst_index_set_resolver (VALUE self)
{
gst_index_set_resolver (RGST_INDEX (self), __resolver,
(gpointer) rb_block_proc ());
return self;
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:7,代码来源:rbgstindex.c
示例6: sig_trap
/*
* call-seq:
* Signal.trap( signal, command ) -> obj
* Signal.trap( signal ) {| | block } -> obj
*
* Specifies the handling of signals. The first parameter is a signal
* name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a
* signal number. The characters ``SIG'' may be omitted from the
* signal name. The command or block specifies code to be run when the
* signal is raised.
* If the command is the string ``IGNORE'' or ``SIG_IGN'', the signal
* will be ignored.
* If the command is ``DEFAULT'' or ``SIG_DFL'', the Ruby's default handler
* will be invoked.
* If the command is ``EXIT'', the script will be terminated by the signal.
* If the command is ``SYSTEM_DEFAULT'', the operating system's default
* handler will be invoked.
* Otherwise, the given command or block will be run.
* The special signal name ``EXIT'' or signal number zero will be
* invoked just prior to program termination.
* trap returns the previous handler for the given signal.
*
* Signal.trap(0, proc { puts "Terminating: #{$$}" })
* Signal.trap("CLD") { puts "Child died" }
* fork && Process.wait
*
* produces:
* Terminating: 27461
* Child died
* Terminating: 27460
*/
static VALUE
sig_trap(int argc, VALUE *argv)
{
struct trap_arg arg;
rb_secure(2);
if (argc < 1 || argc > 2) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
}
arg.sig = trap_signm(argv[0]);
if (argc == 1) {
arg.cmd = rb_block_proc();
arg.func = sighandler;
}
else {
arg.cmd = argv[1];
arg.func = trap_handler(&arg.cmd, arg.sig);
}
if (OBJ_TAINTED(arg.cmd)) {
rb_raise(rb_eSecurityError, "Insecure: tainted signal trap");
}
#if USE_TRAP_MASK
/* disable interrupt */
sigfillset(&arg.mask);
pthread_sigmask(SIG_BLOCK, &arg.mask, &arg.mask);
return rb_ensure(trap, (VALUE)&arg, trap_ensure, (VALUE)&arg);
#else
return trap(&arg);
#endif
}
开发者ID:GunioRobot,项目名称:ruby,代码行数:64,代码来源:signal.c
示例7: define_function
/* call-seq: define_function(name) { |args,...| }
*
* Define a function named +name+ with +args+. The arity of the block
* will be used as the arity for the function defined.
*/
static VALUE define_function(VALUE self, VALUE name)
{
sqlite3RubyPtr ctx;
VALUE block;
int status;
Data_Get_Struct(self, sqlite3Ruby, ctx);
REQUIRE_OPEN_DB(ctx);
block = rb_block_proc();
status = sqlite3_create_function(
ctx->db,
StringValuePtr(name),
rb_proc_arity(block),
SQLITE_UTF8,
(void *)block,
rb_sqlite3_func,
NULL,
NULL
);
CHECK(ctx->db, status);
return self;
}
开发者ID:Accusedbold,项目名称:shoes,代码行数:31,代码来源:database.c
示例8: enumerator_initialize
/*
* call-seq:
* Enumerator.new(size = nil) { |yielder| ... }
* Enumerator.new(obj, method = :each, *args)
*
* Creates a new Enumerator object, which can be used as an
* Enumerable.
*
* In the first form, iteration is defined by the given block, in
* which a "yielder" object, given as block parameter, can be used to
* yield a value by calling the +yield+ method (aliased as +<<+):
*
* fib = Enumerator.new do |y|
* a = b = 1
* loop do
* y << a
* a, b = b, a + b
* end
* end
*
* p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
*
* The optional parameter can be used to specify how to calculate the size
* in a lazy fashion (see Enumerator#size). It can either be a value or
* a callable object.
*
* In the second, deprecated, form, a generated Enumerator iterates over the
* given object using the given method with the given arguments passed.
*
* Use of this form is discouraged. Use Kernel#enum_for or Kernel#to_enum
* instead.
*
* e = Enumerator.new(ObjectSpace, :each_object)
* #-> ObjectSpace.enum_for(:each_object)
*
* e.select { |obj| obj.is_a?(Class) } #=> array of all classes
*
*/
static VALUE
enumerator_initialize(int argc, VALUE *argv, VALUE obj)
{
VALUE recv, meth = sym_each;
VALUE size = Qnil;
if (rb_block_given_p()) {
rb_check_arity(argc, 0, 1);
recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
if (argc) {
if (NIL_P(argv[0]) || rb_obj_is_proc(argv[0]) ||
(RB_TYPE_P(argv[0], T_FLOAT) && RFLOAT_VALUE(argv[0]) == INFINITY)) {
size = argv[0];
} else {
size = rb_to_int(argv[0]);
}
argc = 0;
}
}
else {
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
recv = *argv++;
if (--argc) {
meth = *argv++;
--argc;
}
}
return enumerator_init(obj, recv, meth, argc, argv, 0, size);
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:69,代码来源:enumerator.c
示例9: generator_initialize
/* :nodoc: */
static VALUE
generator_initialize(int argc, VALUE *argv, VALUE obj)
{
VALUE proc;
if (argc == 0) {
rb_need_block();
proc = rb_block_proc();
}
else {
rb_scan_args(argc, argv, "1", &proc);
if (!rb_obj_is_proc(proc))
rb_raise(rb_eTypeError,
"wrong argument type %s (expected Proc)",
rb_obj_classname(proc));
if (rb_block_given_p()) {
rb_warn("given block not used");
}
}
return generator_init(obj, proc);
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:26,代码来源:enumerator.c
示例10: yielder_initialize
/* :nodoc: */
static VALUE
yielder_initialize(VALUE obj)
{
rb_need_block();
return yielder_init(obj, rb_block_proc());
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:8,代码来源:enumerator.c
示例11: rbclt_script_connect_signals
static VALUE
rbclt_script_connect_signals (int argc, VALUE *argv, VALUE self)
{
ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
AutoConnectData data;
data.state = 0;
if (rb_block_given_p ())
{
data.args = rb_ary_new4 (argc, argv);
data.proc = rb_block_proc ();
data.obj = Qnil;
}
else
{
rb_scan_args (argc, argv, "1*", &data.obj, &data.args);
data.proc = Qnil;
}
clutter_script_connect_signals_full (script,
rbclt_script_connect_signal,
&data);
/* If an exception was thrown then continue throwing that now that
we are safely out of the Clutter function call */
if (data.state)
rb_jump_tag (data.state);
return self;
}
开发者ID:orospakr,项目名称:rbclutter,代码行数:31,代码来源:rbcltscript.c
示例12: rb_gsl_multimin_function_new
static VALUE rb_gsl_multimin_function_new(int argc, VALUE *argv, VALUE klass)
{
gsl_multimin_function *F = NULL;
VALUE ary;
size_t i;
F = ALLOC(gsl_multimin_function);
F->f = &rb_gsl_multimin_function_f;
ary = rb_ary_new2(2);
/* (VALUE) F->params = ary;*/
F->params = (void *) ary;
if (rb_block_given_p()) rb_ary_store(ary, 0, rb_block_proc());
else rb_ary_store(ary, 0, Qnil);
rb_ary_store(ary, 1, Qnil);
switch (argc) {
case 0:
break;
case 1:
set_function(0, argv, F);
break;
case 2:
case 3:
for (i = 0; (int) i < argc; i++) set_function(i, argv, F);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments");
}
return Data_Wrap_Struct(klass, gsl_multimin_function_mark, gsl_multimin_function_free, F);
}
开发者ID:AbhimanyuAryan,项目名称:rb-gsl,代码行数:28,代码来源:multimin.c
示例13: lb_set_uri_hook
static VALUE
lb_set_uri_hook(VALUE self)
{
VALUE func = rb_block_proc();
G_RELATIVE(self, func);
gtk_link_button_set_uri_hook((GtkLinkButtonUriFunc)link_func, (gpointer)func, (GDestroyNotify)NULL);
return self;
}
开发者ID:geoffyoungs,项目名称:ruby-gnome2,代码行数:8,代码来源:rbgtklinkbutton.c
示例14: rg_add_watch
static VALUE
rg_add_watch(VALUE self, VALUE condition)
{
VALUE func = rb_block_proc();
G_RELATIVE(self, func);
return UINT2NUM(g_io_add_watch(_SELF(self), NUM2INT(condition),
(GIOFunc)io_func, (gpointer)func));
}
开发者ID:htrb,项目名称:ruby-gnome2,代码行数:8,代码来源:rbglib_iochannel.c
示例15: rg_set_forward_page_func
static VALUE
rg_set_forward_page_func(VALUE self)
{
VALUE func = rb_block_proc();
G_RELATIVE(self, func);
gtk_assistant_set_forward_page_func(_SELF(self), (GtkAssistantPageFunc)ass_page_func, (gpointer)func, NULL);
return self;
}
开发者ID:Mazwak,项目名称:ruby-gnome2,代码行数:8,代码来源:rbgtkassistant.c
示例16: rb_rsvg_handle_set_size_callback
static VALUE
rb_rsvg_handle_set_size_callback(VALUE self)
{
rb_ivar_set(self, id_callback, rb_block_proc());
rsvg_handle_set_size_callback(_SELF(self), exec_callback,
(gpointer)self, NULL);
return self;
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:8,代码来源:rbrsvg.c
示例17: rg_initialize
static VALUE
rg_initialize(VALUE self)
{
GClosure* closure = g_rclosure_new(rb_block_proc(), Qnil, NULL);
G_INITIALIZE(self, closure);
g_closure_sink(closure);
return self;
}
开发者ID:Mazwak,项目名称:ruby-gnome2,代码行数:8,代码来源:rbgobj_closure.c
示例18: rb_aio_s_error
static VALUE
rb_aio_s_error(VALUE aio, VALUE cb)
{
rb_aiocb_t *cbs = GetCBStruct(cb);
if (rb_block_given_p()){
cbs->rcb = rb_block_proc();
}
return rb_aio_err( &cbs->cb );
}
开发者ID:methodmissing,项目名称:aio,代码行数:9,代码来源:aio.c
示例19: rb_gsl_comparison_complex
int rb_gsl_comparison_complex(const void *aa, const void *bb)
{
gsl_complex *a = NULL, *b = NULL;
a = (gsl_complex *) aa;
b = (gsl_complex *) bb;
return FIX2INT(rb_funcall(rb_block_proc(), RBGSL_ID_call, 2,
Data_Wrap_Struct(cgsl_complex, 0, NULL, a),
Data_Wrap_Struct(cgsl_complex, 0, NULL, b)));
}
开发者ID:rbalint,项目名称:rb-gsl,代码行数:9,代码来源:sort.c
示例20: pj_send
static VALUE
pj_send(VALUE self)
{
VALUE block = rb_block_proc();
G_CHILD_ADD(gPrintJob, block);
gtk_print_job_send(_SELF(self), complete_func, (gpointer)block,
remove_callback_reference);
return self;
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:9,代码来源:rbgtkprintjob.c
注:本文中的rb_block_proc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论