当前位置: 首页>>代码示例>>C++>>正文


C++ NativeFunction类代码示例

本文整理汇总了C++中NativeFunction的典型用法代码示例。如果您正苦于以下问题:C++ NativeFunction类的具体用法?C++ NativeFunction怎么用?C++ NativeFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NativeFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_bind_with_unsigned_long

  void test_bind_with_unsigned_long() {
    String* name = String::create(state, "dummy_unsigned_long");

    Array* args = Array::create(state, 1);
    args->set(state, 0, Fixnum::from(RBX_FFI_TYPE_ULONG));

    Object* ret = Fixnum::from(RBX_FFI_TYPE_ULONG);

    NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);

    TS_ASSERT(!func->nil_p());

    Array* input = Array::create(state, 1);
    input->set(state, 0, Fixnum::from(13));

    Arguments args_obj(input);

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT(kind_of<Integer>(out));
    TS_ASSERT_EQUALS(as<Integer>(out)->to_native(), (native_int)13);

    input = Array::create(state, 1);
    input->set(state, 0, Integer::from(state, (unsigned long)2147483647));

    Arguments args_obj2(input);

    out = func->call(state, args_obj2, NULL);

    TS_ASSERT(kind_of<Integer>(out));
    TS_ASSERT_EQUALS(as<Integer>(out)->to_native(), (native_int)2147483647);
  }
开发者ID:atoulme,项目名称:rubinius,代码行数:32,代码来源:test_nativefunction.hpp

示例2: test_bind_with_unsigned_short

  void test_bind_with_unsigned_short() {
    String* name = String::create(state, "dummy_unsigned_short");

    Array* args = Array::create(state, 1);
    args->set(state, 0, Fixnum::from(RBX_FFI_TYPE_USHORT));

    Object* ret = Fixnum::from(RBX_FFI_TYPE_USHORT);

    NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);

    TS_ASSERT(!func->nil_p());

    Array* input = Array::create(state, 2);
    input->set(state, 0, Fixnum::from(0));

    Arguments args_obj(input);

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT(kind_of<Fixnum>(out));

    input = Array::create(state, 2);
    input->set(state, 0, out);

    Arguments args_obj2(input);

    out = func->call(state, args_obj2, NULL);

    TS_ASSERT(kind_of<Fixnum>(out));
    TS_ASSERT_EQUALS(out, Fixnum::from(0));
  }
开发者ID:atoulme,项目名称:rubinius,代码行数:31,代码来源:test_nativefunction.hpp

示例3: execute

  /* Run when a NativeFunction is executed.  Executes the related C function.
   */
  ExecuteStatus NativeFunction::execute(STATE, Task* task, Message& msg) {
    NativeFunction* nfunc = as<NativeFunction>(msg.method);

    Object* obj = nfunc->call(state, &msg);

    task->push(obj);

    return cExecuteContinue;
  }
开发者ID:marnen,项目名称:rubinius,代码行数:11,代码来源:nativefunction.cpp

示例4: test_bind_with_void

  void test_bind_with_void() {
    Pointer* name = Pointer::create(state, (void*)dummy_void);

    Array* args = Array::create(state, 0);

    Object* ret = Fixnum::from(RBX_FFI_TYPE_VOID);

    NativeFunction *func = NativeFunction::generate(state, name, state->symbol("ffi"), args, ret);

    TS_ASSERT(!func->nil_p());

    Arguments args_obj;

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT_EQUALS(out, Qnil);
  }
开发者ID:aemoncannon,项目名称:rubinius,代码行数:17,代码来源:test_nativefunction.hpp

示例5: test_bind_with_void

  void test_bind_with_void() {
    String* name = String::create(state, "dummy_void");

    Array* args = Array::create(state, 0);

    Object* ret = Fixnum::from(RBX_FFI_TYPE_VOID);

    NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);

    TS_ASSERT(!func->nil_p());

    Arguments args_obj;

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT_EQUALS(out, Qnil);
  }
开发者ID:atoulme,项目名称:rubinius,代码行数:17,代码来源:test_nativefunction.hpp

示例6: create

  NativeFunction* NativeFunction::create(STATE, Object* name, int args) {
    NativeFunction* nf = (NativeFunction*)state->new_object(G(native_function));
    nf->primitive(state, state->symbol("nativefunction_call"));
    nf->required(state, Fixnum::from(args));
    nf->serial(state, Fixnum::from(0));
    nf->name(state, name);
    nf->file(state, state->symbol("<system>"));
    nf->data(state, (MemoryPointer*)Qnil);

    nf->set_executor(NativeFunction::execute);

    return nf;
  }
开发者ID:marnen,项目名称:rubinius,代码行数:13,代码来源:nativefunction.cpp

示例7: test_bind_with_string_and_ptr_for_null

  void test_bind_with_string_and_ptr_for_null() {
    Array* args = Array::create(state, 0);

    Object* ret = Fixnum::from(RBX_FFI_TYPE_STRPTR);

    String* name = String::create(state, "null_string");

    NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);

    TS_ASSERT(!func->nil_p());

    Arguments args_obj;

    Array* out = try_as<Array>(func->call(state, args_obj, NULL));

    TS_ASSERT(kind_of<Array>(out));

    TS_ASSERT_EQUALS(out->get(state, 0), Qnil);
    TS_ASSERT_EQUALS(out->get(state, 1), Qnil);
  }
开发者ID:atoulme,项目名称:rubinius,代码行数:20,代码来源:test_nativefunction.hpp

示例8: test_bind_with_string_and_ptr_for_null

  void test_bind_with_string_and_ptr_for_null() {
    Array* args = Array::create(state, 0);

    Object* ret = Fixnum::from(RBX_FFI_TYPE_STRPTR);

    Pointer* name = Pointer::create(state, (void*)null_string);

    NativeFunction *func = NativeFunction::generate(state, name, state->symbol("ffi"), args, ret);

    TS_ASSERT(!func->nil_p());

    Arguments args_obj;

    Array* out = try_as<Array>(func->call(state, args_obj, NULL));

    TS_ASSERT(kind_of<Array>(out));

    TS_ASSERT_EQUALS(out->get(state, 0), Qnil);
    TS_ASSERT_EQUALS(out->get(state, 1), Qnil);
  }
开发者ID:aemoncannon,项目名称:rubinius,代码行数:20,代码来源:test_nativefunction.hpp

示例9: execute

  /* Run when a NativeFunction is executed.  Executes the related C function.
   */
  Object* NativeFunction::execute(STATE, CallFrame* call_frame, Dispatch& msg,
                                  Arguments& args) {
    NativeFunction* nfunc = as<NativeFunction>(msg.method);

    state->set_call_frame(call_frame);

#ifdef RBX_PROFILER
    if(unlikely(state->shared.profiling()))
      state->profiler()->enter_method(msg, args);
#endif

    Object* obj = nfunc->call(state, args);

#ifdef RBX_PROFILER
    if(unlikely(state->shared.profiling()))
      state->profiler()->leave();
#endif

    return obj;
  }
开发者ID:,项目名称:,代码行数:22,代码来源:

示例10: test_bind_with_state

  void test_bind_with_state() {
    global_state = state;

    String* name = String::create(state, "dummy_state");

    Array* args = Array::create(state, 1);
    args->set(state, 0, Fixnum::from(RBX_FFI_TYPE_STATE));

    Object* ret = Fixnum::from(RBX_FFI_TYPE_INT);

    NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);

    TS_ASSERT(!func->nil_p());

    Arguments args_obj;

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT(kind_of<Fixnum>(out));
    TS_ASSERT(as<Fixnum>(out)->to_native());
  }
开发者ID:atoulme,项目名称:rubinius,代码行数:21,代码来源:test_nativefunction.hpp

示例11: test_bind_with_state

  void test_bind_with_state() {
    global_state = state;

    Pointer* name = Pointer::create(state, (void*)dummy_state);

    Array* args = Array::create(state, 1);
    args->set(state, 0, Fixnum::from(RBX_FFI_TYPE_STATE));

    Object* ret = Fixnum::from(RBX_FFI_TYPE_INT);

    NativeFunction *func = NativeFunction::generate(state, name, state->symbol("ffi"), args, ret);

    TS_ASSERT(!func->nil_p());

    Arguments args_obj;

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT(kind_of<Fixnum>(out));
    TS_ASSERT(as<Fixnum>(out)->to_native());
  }
开发者ID:aemoncannon,项目名称:rubinius,代码行数:21,代码来源:test_nativefunction.hpp

示例12: test_bind_with_double

  void test_bind_with_double() {
    Pointer* name = Pointer::create(state, (void*)dummy_double);

    Array* args = Array::create(state, 1);
    args->set(state, 0, Fixnum::from(RBX_FFI_TYPE_DOUBLE));

    Object* ret = Fixnum::from(RBX_FFI_TYPE_DOUBLE);

    NativeFunction *func = NativeFunction::generate(state, name, state->symbol("ffi"), args, ret);

    TS_ASSERT(!func->nil_p());

    Array* input = Array::create(state, 1);
    input->set(state, 0, Float::create(state, 13.2));

    Arguments args_obj(input);

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT(kind_of<Float>(out));
    TS_ASSERT_EQUALS(as<Float>(out)->val, 13.2);
  }
开发者ID:aemoncannon,项目名称:rubinius,代码行数:22,代码来源:test_nativefunction.hpp

示例13: test_bind_with_double

  void test_bind_with_double() {
    String* name = String::create(state, "dummy_double");

    Array* args = Array::create(state, 1);
    args->set(state, 0, Fixnum::from(RBX_FFI_TYPE_DOUBLE));

    Object* ret = Fixnum::from(RBX_FFI_TYPE_DOUBLE);

    NativeFunction *func = NativeFunction::bind(state, Qnil, name, args, ret);

    TS_ASSERT(!func->nil_p());

    Array* input = Array::create(state, 1);
    input->set(state, 0, Float::create(state, 13.2));

    Arguments args_obj(input);

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT(kind_of<Float>(out));
    TS_ASSERT_EQUALS(as<Float>(out)->val, 13.2);
  }
开发者ID:atoulme,项目名称:rubinius,代码行数:22,代码来源:test_nativefunction.hpp

示例14: test_bind_with_short

  void test_bind_with_short() {
    Pointer* name = Pointer::create(state, (void*)dummy_short);

    Array* args = Array::create(state, 1);
    args->set(state, 0, Fixnum::from(RBX_FFI_TYPE_SHORT));

    Object* ret = Fixnum::from(RBX_FFI_TYPE_SHORT);

    NativeFunction *func = NativeFunction::generate(state, name, state->symbol("ffi"), args, ret);

    TS_ASSERT(!func->nil_p());

    Array* input = Array::create(state, 1);
    input->set(state, 0, Fixnum::from(13));

    Arguments args_obj(input);

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT(kind_of<Fixnum>(out));
    TS_ASSERT_EQUALS(as<Fixnum>(out)->to_native(), 13);
  }
开发者ID:aemoncannon,项目名称:rubinius,代码行数:22,代码来源:test_nativefunction.hpp

示例15: test_bind_with_string

  void test_bind_with_string() {
    Pointer* name = Pointer::create(state, (void*)strlen);

    Array* args = Array::create(state, 1);
    args->set(state, 0, Fixnum::from(RBX_FFI_TYPE_STRING));

    Object* ret = Fixnum::from(RBX_FFI_TYPE_INT);

    NativeFunction *func = NativeFunction::generate(state, name, state->symbol("ffi"), args, ret);

    TS_ASSERT(!func->nil_p());

    Array* input = Array::create(state, 1);
    input->set(state, 0, String::create(state, "strlen"));

    Arguments args_obj(input);

    Object* out = func->call(state, args_obj, NULL);

    TS_ASSERT(out->fixnum_p());
    TS_ASSERT_EQUALS(as<Integer>(out)->to_native(), 6);
  }
开发者ID:aemoncannon,项目名称:rubinius,代码行数:22,代码来源:test_nativefunction.hpp


注:本文中的NativeFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。