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


C++ NativeFunction::nil_p方法代码示例

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


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

示例1: test_bind_with_long_long

  void test_bind_with_long_long() {
    String* name = String::create(state, "dummy_long_long");

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

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

    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, 9223372036854775807LL));

    Arguments args_obj2(input);

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

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

示例2: test_bind_with_unsigned_long_long

  void test_bind_with_unsigned_long_long() {
    Pointer* name = Pointer::create(state, (void*)dummy_unsigned_long_long);

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

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

    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<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, 9223372036854775808ULL));

    Arguments args_obj2(input);

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

    TS_ASSERT(kind_of<Bignum>(out));
    TS_ASSERT_EQUALS(as<Bignum>(out)->to_ulong_long(), 9223372036854775808ULL);
  }
开发者ID:aemoncannon,项目名称:rubinius,代码行数:32,代码来源:test_nativefunction.hpp

示例3: 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

示例4: test_bind_with_unsigned_short

  void test_bind_with_unsigned_short() {
    Pointer* name = Pointer::create(state, (void*)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::generate(state, name, state->symbol("ffi"), 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:aemoncannon,项目名称:rubinius,代码行数:31,代码来源:test_nativefunction.hpp

示例5: test_bind_with_int

  void test_bind_with_int() {
    Pointer* name = Pointer::create(state, (void*)dummy_int);

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

    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, 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, (int)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:aemoncannon,项目名称:rubinius,代码行数:32,代码来源:test_nativefunction.hpp

示例6: test_bind_with_unsigned_int

  void test_bind_with_unsigned_int() {
    String* name = String::create(state, "dummy_unsigned_int");

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

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

    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 int)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

示例7: test_bind_with_ptr

  void test_bind_with_ptr() {
    Pointer* name = Pointer::create(state, (void*)dummy_ptr);

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

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

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

    TS_ASSERT(!func->nil_p());

    char buffer[1];
    buffer[0] = 0;
    Pointer* ptr = Pointer::create(state, buffer);

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

    Arguments args_obj(input);

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

    TS_ASSERT(kind_of<Pointer>(out));
    TS_ASSERT_EQUALS(as<Pointer>(out)->pointer, ptr->pointer);

    input = Array::create(state, 1);
    input->set(state, 0, Qnil);

    Arguments args_obj2(input);

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

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

示例8: test_bind_with_string_and_ptr

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

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

    Pointer* name = Pointer::create(state, (void*)static_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));

    String* o1 = try_as<String>(out->get(state, 0));
    Pointer* o2 = try_as<Pointer>(out->get(state, 1));
    TS_ASSERT(kind_of<String>(o1));
    TS_ASSERT(kind_of<Pointer>(o2));

    TS_ASSERT_EQUALS(o1->c_str(), std::string("static strings are fun"));
    TS_ASSERT(strcmp((char*)(o2->pointer), "static strings are fun") == 0);
  }
开发者ID:aemoncannon,项目名称:rubinius,代码行数:25,代码来源:test_nativefunction.hpp

示例9: test_bind_with_string_returned

  void test_bind_with_string_returned() {
    Pointer* name = Pointer::create(state, (void*)dummy_string);

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

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

    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, "whatever"));

    Arguments args_obj(input);

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

    TS_ASSERT(kind_of<String>(out));
    TS_ASSERT_EQUALS(as<String>(out)->c_str(), std::string("whatever"));

    input = Array::create(state, 1);
    input->set(state, 0, Qnil);

    Arguments args_obj2(input);

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

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

示例10: test_bind_with_object

  void test_bind_with_object() {
    String* name = String::create(state, "dummy_ptr");

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

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

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

    TS_ASSERT(!func->nil_p());

    Array* input = Array::create(state, 1);
    Object* obj = state->new_object<Object>(G(object));
    input->set(state, 0, obj);

    Arguments args_obj(input);

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

    TS_ASSERT(kind_of<Object>(out));
    TS_ASSERT_EQUALS(out, obj);

    input = Array::create(state, 1);
    input->set(state, 0, Qnil);

    Arguments args_obj2(input);

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

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

示例11: test_bind_with_object

  void test_bind_with_object() {
    Pointer* name = Pointer::create(state, (void*)dummy_ptr);

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

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

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

    TS_ASSERT(!func->nil_p());

    Array* input = Array::create(state, 1);
    Object* obj = state->new_object<Object>(G(object));
    input->set(state, 0, obj);

    Arguments args_obj(input);

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

    TS_ASSERT(kind_of<Object>(out));
    TS_ASSERT_EQUALS(out, obj);

    input = Array::create(state, 1);
    input->set(state, 0, Qnil);

    Arguments args_obj2(input);

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

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

示例12: test_bind_with_ptr

  void test_bind_with_ptr() {
    String* name = String::create(state, "dummy_ptr");

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

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

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

    TS_ASSERT(!func->nil_p());

    char buffer[1];
    buffer[0] = 0;
    MemoryPointer* ptr = MemoryPointer::create(state, buffer);

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

    Arguments args_obj(input);

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

    TS_ASSERT(kind_of<MemoryPointer>(out));
    TS_ASSERT_EQUALS(as<MemoryPointer>(out)->pointer, ptr->pointer);

    input = Array::create(state, 1);
    input->set(state, 0, Qnil);

    Arguments args_obj2(input);

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

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

示例13: 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

示例14: 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

示例15: 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


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