Exemplo n.º 1
0
static int Paug_init(lua_State *L)
{
    augeas **a;
    struct aug_flagmap *f;
    const char *root = NULL, *loadpath = NULL;
    int flags = 0;

    if (lua_istable(L, 1)) {
        root = get_opt_string_field(L, 1, "root", NULL);
        loadpath = get_opt_string_field(L, 1, "loadpath", NULL);
        for (f = Taug_flagmap; f->name != NULL; f++)
            if (get_boolean_field(L, 1, f->name))
                flags |= f->value;
    } else {
        root = luaL_optstring(L, 1, NULL);
        loadpath = luaL_optstring(L, 2, NULL);
        flags = luaL_optinteger(L, 3, AUG_NONE);
    }

    a = (augeas **) lua_newuserdata(L, sizeof(augeas *));
    luaL_getmetatable(L, PAUG_META);
    lua_setmetatable(L, -2);

    *a = aug_init(root, loadpath, flags);
    if (*a == NULL)
        luaL_error(L, "aug_init failed");
    return 1;
}
Exemplo n.º 2
0
static int get_dbopts(lua_State *L, int i, struct apk_db_options *o)
{
	struct flagmap *f;
	o->root = (char *)get_opt_string_field(L, i, "root", NULL);
	o->repositories_file = (char *)get_opt_string_field(L, i, "repositories_file", NULL);
	o->keys_dir = (char *)get_opt_string_field(L, i, "keys_dir", NULL);
	o->lock_wait = get_opt_int_field(L, i, "lock_wait", 0);
	for (f = opendb_flagmap; f->name != NULL; f++)
		if (get_boolean_field(L, i, f->name))
			o->open_flags |= f->flag;
	return 0;
}