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


C++ enif_make_string函数代码示例

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


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

示例1: setup_2

static ERL_NIF_TERM setup_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	unsigned int channel;
	unsigned long speed;
	int error;

	if (argc != 2 || !enif_is_number(env, argv[0]) || !enif_is_number(env, argv[1])) {
		return enif_make_badarg(env);
	}
	if (!enif_get_uint(env, argv[0], &channel)) {
		return enif_make_badarg(env);
	}
	if (!enif_get_ulong(env, argv[1], &speed)) {
		return enif_make_badarg(env);
	}
	if (speed < 500000 || speed > 32000000) {
		return enif_make_badarg(env);
	}
	switch (channel) {
		case 0:
			if (state0.fd != 0) {
				return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_string(env, "channel already opened", ERL_NIF_LATIN1));
			}
			else {
				state0.env = env;
				state0.fd = wiringPiSPISetup(channel, speed);
				if (state0.fd == 0) {
					error = errno;
					return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_int(env, error));
				}
				else {
					return enif_make_tuple2(env, enif_make_atom(env, "ok"), enif_make_int(env, channel));
				}
			}
			break;
		case 1:
			if (state1.fd != 0) {
				return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_string(env, "channel already opened", ERL_NIF_LATIN1));
			}
			else {
				state1.env = env;
				state1.fd = wiringPiSPISetup(channel, speed);
				if (state1.fd == 0) {
					error = errno;
					return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_int(env, error));
				}
				else {
					return enif_make_tuple2(env, enif_make_atom(env, "ok"), enif_make_int(env, channel));
				}
			}
			break;
		default:
			return enif_make_badarg(env);
	}
}
开发者ID:sivieri,项目名称:spidev2,代码行数:54,代码来源:spidev.c

示例2: pynerl_obj_to_term

// convert a python object to an erlang term, return the atom 'unknown' if
// the type can't be converted
static ERL_NIF_TERM pynerl_obj_to_term(ErlNifEnv* env, PyObject* obj) {
	ERL_NIF_TERM term;

	if (obj == Py_False) {
		term = enif_make_atom(env, "false");
	}
	else if (obj == Py_True) {
		term = enif_make_atom(env, "true");
	}
	else if (PyLong_Check(obj)) {
		// TODO: make ints when the size allows to.
		term = enif_make_long(env, PyLong_AsLong(obj));
	}
	else if (PyFloat_Check(obj)) {
		term = enif_make_double(env, PyFloat_AsDouble(obj));
	}
	else if (PyTuple_Check(obj)) {
		Py_ssize_t i, arity = PyTuple_Size(obj);
		ERL_NIF_TERM *terms = (ERL_NIF_TERM*) malloc(sizeof(ERL_NIF_TERM) * (int)arity);

		for (i = 0; i < arity; i++) {
			terms[(int)i] = pynerl_obj_to_term(env, PyTuple_GetItem(obj, i));
		}

		term = enif_make_tuple_from_array(env, terms, (unsigned int)arity);
	}
	else if (PyBytes_Check(obj)) {
		// XXX: the encoding must be latin1
		term = enif_make_string(env, PyBytes_AsString(obj), ERL_NIF_LATIN1);
	}
	else if (PyUnicode_Check(obj)) {
		// XXX: the encoding must be latin1
		term = enif_make_string(env, PyBytes_AsString(PyUnicode_AsLatin1String(obj)), ERL_NIF_LATIN1);
	}
	else if (PyList_Check(obj)) {
		Py_ssize_t i, arity = PyList_Size(obj);
		ERL_NIF_TERM *terms = (ERL_NIF_TERM*) malloc(sizeof(ERL_NIF_TERM) * (int)arity);

		for (i = 0; i < arity; i++) {
			terms[(int)i] = pynerl_obj_to_term(env, PyList_GetItem(obj, i));
		}

		term = enif_make_list_from_array(env, terms, (unsigned int)arity);
	}
	else if (obj == Py_None) {
		term = enif_make_atom(env, "none");
    }
	else {
		term = enif_make_atom(env, "unknown");
    }

	return term;
}
开发者ID:marianoguerra,项目名称:pynerl,代码行数:55,代码来源:pynerl.c

示例3: make_strings

static ERL_NIF_TERM make_strings(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    const char a0string[8] = {'a','0','s','t','r','i','n','g'};
    const char a0string0[9] = {'a','\0','s','t','r','i','n','g',0};
    const char astringwith8bits[37] = {'E','r','l','a','n','g',' ',0xE4 /* 'ä' */,'r',' ','e','t','t',' ','g','e','n','e','r','e','l','l','t',' ','p','r','o','g','r','a','m','s','p','r', 0xE5 /* 'å' */,'k',0};

    return enif_make_tuple5(env,
			    enif_make_string(env, "a0string", ERL_NIF_LATIN1),
			    enif_make_string_len(env, "a0string", 8, ERL_NIF_LATIN1),
			    enif_make_string_len(env, a0string, 8, ERL_NIF_LATIN1),
			    enif_make_string_len(env, a0string0, 9, ERL_NIF_LATIN1),
			    enif_make_string(env, astringwith8bits, ERL_NIF_LATIN1));
}
开发者ID:cristiangreco,项目名称:otp,代码行数:13,代码来源:nif_SUITE.c

示例4: error_tuple

static ERL_NIF_TERM
error_tuple(ErlNifEnv *env, char *err)
{
    return enif_make_tuple(env, 2,
                           atom_error,
                           enif_make_string(env, err, ERL_NIF_LATIN1));
}
开发者ID:alepharchives,项目名称:cerck,代码行数:7,代码来源:cerck.c

示例5: visitor_enum_cb

static enum CXChildVisitResult
visitor_enum_cb(CXCursor cursor, CXCursor parent, CXClientData client_data) {
  EnumData* data = (EnumData*)client_data;
  ErlNifEnv *env = data->env;
  ERL_NIF_TERM name;
  ERL_NIF_TERM value;
  long long cvalue;

  CXString tmp;
  char* cstr;

  switch (clang_getCursorKind(cursor)) {
    case CXCursor_EnumConstantDecl: {
      tmp = clang_getCursorSpelling(cursor);
      cstr = (char*)clang_getCString(tmp);
      cvalue = clang_getEnumConstantDeclValue(cursor);
      name = enif_make_string(env, cstr, ERL_NIF_LATIN1);
      value = enif_make_int64(env, cvalue);
      data->enum_values = enif_make_list_cell(env,
                                              enif_make_tuple2(env, name, value),
                                              data->enum_values);
    }
    default: {
      return CXChildVisit_Continue;
    }
  }
}
开发者ID:parapluu,项目名称:nifty,代码行数:27,代码来源:nifty_clangparse.c

示例6: get_driver

/* OGRSFDriverH CPL_DLL OGRGetDriver( int );

{ok, Driver} = lgeo_ogr:get_driver(0),

*/
static ERL_NIF_TERM
get_driver(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int driver_idx;
    ERL_NIF_TERM eterm;

    if (argc != 1) {
        return enif_make_badarg(env);
    }

    if (!enif_get_int(env, argv[0], &driver_idx)) {
        return enif_make_badarg(env);
    }

    OGRSFDriverH drv = OGRGetDriver(driver_idx);

    if (!drv) {
        return enif_make_tuple2(env,
            enif_make_atom(env, "error"),
            enif_make_string(env, "Driver not found", ERL_NIF_LATIN1));
    }

    OGRSFDriverH **driver = \
        enif_alloc_resource(OGR_D_RESOURCE, sizeof(OGRSFDriverH*));
    *driver = drv;

    eterm = enif_make_resource(env, driver);
    enif_release_resource(driver);
    return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm);
}
开发者ID:namjae,项目名称:lgeo,代码行数:35,代码来源:lgeo_ogr.c

示例7: g_export_to_wkt

/* OGR_G_ExportToWkt(OGRGeometryH, char **)

{ok, DataSource} = lgeo_ogr:open("test/polygon.shp"),
{ok, Layer} = lgeo_ogr:ds_get_layer(DataSource, 0),
{ok, Feature} = lgeo_ogr:l_get_feature(Layer, 0),
{ok, Geometry} = lgeo_ogr:f_get_geometry_ref(Feature),
{ok, Wkt} = lgeo_ogr:g_export_to_wkt(Geometry).

*/
static ERL_NIF_TERM
g_export_to_wkt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    EnvGeometry_t **geom;
    ERL_NIF_TERM eterm;

    if (argc != 1) {
        return enif_make_badarg(env);
    }

    if (!enif_get_resource(env, argv[0], OGR_G_RESOURCE, (void**)&geom)) {
        return enif_make_badarg(env);
    }

    char *wkt = NULL;
    OGRErr eErr = OGR_G_ExportToWkt((**geom).obj, &wkt);
    if (eErr != OGRERR_NONE) {
        return enif_make_tuple2(env,
            enif_make_atom(env, "error"),
            enif_make_int(env, eErr));
    }

    eterm = enif_make_string(env, wkt, ERL_NIF_LATIN1);
    OGRFree(wkt);
    return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm);
}
开发者ID:namjae,项目名称:lgeo,代码行数:35,代码来源:lgeo_ogr.c

示例8: fd_get_fields_type

/*

{ok, DataSource} = lgeo_ogr:open("test/polygon.shp"),
{ok, Layer} = lgeo_ogr:ds_get_layer(DataSource, 0),
{ok, FeatureDefn} = lgeo_ogr:l_get_layer_defn(Layer),
{ok, Types} = lgeo_ogr:fd_get_fields_type(FeatureDefn).
{"Integer","String"}
*/
static ERL_NIF_TERM
fd_get_fields_type(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    EnvFeatureDefn_t **feat_defn;
    ERL_NIF_TERM eterm;

    if (argc != 1) {
        return enif_make_badarg(env);
    }

    if(!enif_get_resource(env, argv[0], OGR_FD_RESOURCE, (void**)&feat_defn)) {
        return enif_make_badarg(env);
    }

    int count = OGR_FD_GetFieldCount((**feat_defn).obj);
    ERL_NIF_TERM *arr = (ERL_NIF_TERM *) malloc(sizeof(ERL_NIF_TERM)*count);
    int index;
    for(index=0; index<count; index++)
    {
        OGRFieldDefnH field_defn = OGR_FD_GetFieldDefn((**feat_defn).obj, index);
        arr[index] = enif_make_string(env,
            OGR_GetFieldTypeName(OGR_Fld_GetType(field_defn)),
            ERL_NIF_LATIN1);
    }

    eterm = enif_make_tuple_from_array(env, arr, index);
    free(arr);
    return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm);
}
开发者ID:namjae,项目名称:lgeo,代码行数:37,代码来源:lgeo_ogr.c

示例9: format_error

static ERL_NIF_TERM format_error(ErlNifEnv* env, int argc,
				 const ERL_NIF_TERM argv[])
{
  unsigned len;
  int res;

  if (!enif_get_atom_length(env, argv[0], &len, ERL_NIF_LATIN1))
    return enif_make_badarg(env);

  char *atom = malloc(len+1);
  if (!enif_get_atom(env, argv[0], atom, len+1, ERL_NIF_LATIN1)) {
    free(atom);
    return enif_make_badarg(env);
  }

  if (!strcmp("done", atom)) res = RS_DONE;
  else if (!strcmp("blocked", atom)) res = RS_BLOCKED;
  else if (!strcmp("running", atom)) res = RS_RUNNING;
  else if (!strcmp("test_skipped", atom)) res = RS_TEST_SKIPPED;
  else if (!strcmp("io_error", atom)) res = RS_IO_ERROR;
  else if (!strcmp("syntax_error", atom)) res = RS_SYNTAX_ERROR;
  else if (!strcmp("mem_error", atom)) res = RS_MEM_ERROR;
  else if (!strcmp("input_ended", atom)) res = RS_INPUT_ENDED;
  else if (!strcmp("bad_magic", atom)) res = RS_BAD_MAGIC;
  else if (!strcmp("unimplemented", atom)) res = RS_UNIMPLEMENTED;
  else if (!strcmp("corrupt", atom)) res = RS_CORRUPT;
  else if (!strcmp("internal_error", atom)) res = RS_INTERNAL_ERROR;
  else if (!strcmp("param_error", atom)) res = RS_PARAM_ERROR;
  else res = -1;

  free(atom);

  return enif_make_string(env, rs_strerror(res), ERL_NIF_LATIN1);
}
开发者ID:zinid,项目名称:erlang-rsync,代码行数:34,代码来源:rsync.c

示例10: element_to

static ERL_NIF_TERM element_to(ErlNifEnv* env, int argc,
			       const ERL_NIF_TERM argv[],
			       int as_string)
{
  ErlNifBinary output;
  ERL_NIF_TERM result;
  struct buf *rbuf;

  if (argc == 1) {
    rbuf = init_buf(env);
    if (make_element(env, rbuf, argv[0])) {
      if (as_string) {
	(rbuf->b)[rbuf->len] = 0;
	result = enif_make_string(env, (char *) rbuf->b, ERL_NIF_LATIN1);
	destroy_buf(env, rbuf);
	return result;
      }	else {
	if (ENIF_ALLOC_BINARY(rbuf->len, &output)) {
	  memcpy(output.data, rbuf->b, rbuf->len);
	  result = enif_make_binary(env, &output);
	  destroy_buf(env, rbuf);
	  return result;
	};
      };
    };
    destroy_buf(env, rbuf);
  };
  
  return enif_make_badarg(env);
}
开发者ID:James1133,项目名称:ejabberd,代码行数:30,代码来源:xml.c

示例11: ewpcap_error

void
ewpcap_error(EWPCAP_STATE *ep, char *msg)
{
    int rv = 0;

    if (ep->p == NULL)
        return;

    /* {ewpcap_error, Ref, Error} */
    rv = enif_send(
             NULL,
             &ep->pid,
             ep->env,
             enif_make_tuple3(ep->env,
                              atom_ewpcap_error,
                              enif_make_copy(ep->env, ep->ref),
                              enif_make_string(ep->env, msg, ERL_NIF_LATIN1)
                             )
         );

    if (!rv)
        pcap_breakloop(ep->p);

    enif_clear_env(ep->env);
}
开发者ID:hfeeki,项目名称:ewpcap,代码行数:25,代码来源:ewpcap.c

示例12: newstate

static ERL_NIF_TERM
newstate(ErlNifEnv *env, ErlNifEnv *hold_env)
{
    ERL_NIF_TERM ret;
    lua_State *L;
    elua_t *res;

    L = luaL_newstate();
    if(L==NULL) {
        return enif_make_tuple2(env, atom_error, enif_make_string(env, STR_NOT_ENOUGHT_MEMORY, ERL_NIF_LATIN1));
    }

    luaL_openlibs(L);

    res = enif_alloc_resource(RES_SYNC, sizeof(elua_t));
    if(res == NULL) return enif_make_badarg(env);

    //printf("alloc res 0x%x\n" ,(unsigned int)res);

    ret = enif_make_resource(env, res);
    enif_release_resource(res);

    res->L = L;

    return enif_make_tuple2(env, atom_ok, ret);
}
开发者ID:indie21,项目名称:elua,代码行数:26,代码来源:elua.c

示例13: parse

static ERL_NIF_TERM parse(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    XML_Parser **parser;
    int is_final, res, errcode;
    ErlNifBinary stream;
    char *errstring;

    assert(argc == 3);

    if (!enif_get_resource(env, argv[0], PARSER_POINTER, (void **)&parser))
        return enif_make_badarg(env);

    if (!enif_is_binary(env, argv[1]))
        return enif_make_badarg(env);

    enif_get_int(env, argv[2], &is_final);
    enif_inspect_binary(env, argv[1], &stream);

    expat_parser *parser_data = XML_GetUserData((XML_Parser)(*parser));
    parser_data->result = enif_make_list(env, 0);
    parser_data->env = env;
    XML_SetUserData((XML_Parser)(*parser), parser_data);

    res = XML_Parse((XML_Parser)(*parser), (const char *)stream.data, stream.size, is_final);
    if(!res)
        {
            errcode = XML_GetErrorCode((XML_Parser)(*parser));
            errstring = (char *)XML_ErrorString(errcode);

            return enif_make_tuple(env, 2, ERROR,
                                   enif_make_string(env, errstring, ERL_NIF_LATIN1));
        }

    return enif_make_tuple(env, 2, OK, parser_data->result);
};
开发者ID:erszcz,项目名称:exml,代码行数:35,代码来源:exml_event.c

示例14: float_ref

static ERL_NIF_TERM
float_ref(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  int err;
  double helper;
  float *value;
  
  value = enif_alloc(sizeof(float));
  if (!value) {
    goto error;
  }

  err = enif_get_double(env, argv[0], &helper);
  if (!err) {
    enif_free(value);
    goto error;
  }

  *value = (float)helper;
  
  return enif_make_tuple2(env, 
			  nifty_make_ptr(env, (ptr_t)value),
			  enif_make_string(env, "nifty.float *", ERL_NIF_LATIN1));

 error:
  return enif_make_badarg(env);
}
开发者ID:276361270,项目名称:nifty,代码行数:27,代码来源:nifty.c

示例15: list_to_cstr

static ERL_NIF_TERM
list_to_cstr(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  int err, written, tmp;
  unsigned int l;
  char* cstr;

  err = enif_get_list_length(env, argv[0], &l);
  if (!err) {
    goto error;
  }
  l+=1; // Null Termination
  cstr = enif_alloc(sizeof(char)*l);
  if (!cstr) {
    goto error;
  }
  written = 0;
  while (written<(l)) {
    tmp = enif_get_string(env, argv[0], cstr+written, l-written, ERL_NIF_LATIN1);
    if (tmp<=0) {
      enif_free(cstr);
      goto error;
    }
    written += tmp;
  }

  return enif_make_tuple2(env,
			  enif_make_int64(env, (ptr_t)cstr),
			  enif_make_string(env, "nifty.char *", ERL_NIF_LATIN1));

 error:
  return enif_make_badarg(env);
}
开发者ID:276361270,项目名称:nifty,代码行数:33,代码来源:nifty.c


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