Пример #1
0
int map_to_color(ErlNifEnv* env, ERL_NIF_TERM map, SDL_Color* color)
{
	ERL_NIF_TERM r, g, b, a;
	unsigned int ri, gi, bi, ai;

	if (!enif_get_map_value(env, map, atom_r, &r))
		return 0;
	if (!enif_get_map_value(env, map, atom_g, &g))
		return 0;
	if (!enif_get_map_value(env, map, atom_b, &b))
		return 0;
	if (!enif_get_map_value(env, map, atom_a, &a))
		return 0;

	if (!enif_get_uint(env, r, &ri))
		return 0;
	if (!enif_get_uint(env, g, &gi))
		return 0;
	if (!enif_get_uint(env, b, &bi))
		return 0;
	if (!enif_get_uint(env, a, &ai))
		return 0;

	color->r = ri;
	color->g = gi;
	color->b = bi;
	color->a = ai;

	return 1;
}
Пример #2
0
int get_engine_and_key_id(ErlNifEnv *env, ERL_NIF_TERM key, char ** id, ENGINE **e)
{
    ERL_NIF_TERM engine_res, key_id_term;
    struct engine_ctx *ctx;
    ErlNifBinary key_id_bin;

    if (!enif_get_map_value(env, key, atom_engine, &engine_res))
        goto err;
    if (!enif_get_resource(env, engine_res, engine_ctx_rtype, (void**)&ctx))
        goto err;
    if (!enif_get_map_value(env, key, atom_key_id, &key_id_term))
        goto err;
    if (!enif_inspect_binary(env, key_id_term, &key_id_bin))
        goto err;

    *e = ctx->engine;
    return zero_terminate(key_id_bin, id);

 err:
    return 0;
}
Пример #3
0
static ERL_NIF_TERM enabled(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int state_arity;
    const ERL_NIF_TERM *state_tuple;
    ERL_NIF_TERM value;
    ASSERT(argc == 3);

    if (!enif_get_tuple(env, argv[1], &state_arity, &state_tuple))
        return atom_discard;

    if (enif_get_map_value(env, state_tuple[0], argv[0], &value)) {
        return value;
    } else {
        return atom_discard;
    }
}
Пример #4
0
char *get_key_password(ErlNifEnv *env, ERL_NIF_TERM key) {
    ERL_NIF_TERM tmp_term;
    ErlNifBinary pwd_bin;
    char *pwd = NULL;

    if (!enif_get_map_value(env, key, atom_password, &tmp_term))
        goto err;
    if (!enif_inspect_binary(env, tmp_term, &pwd_bin))
        goto err;
    if (!zero_terminate(pwd_bin, &pwd))
        goto err;

    return pwd;

 err:
    return NULL;
}