Exemplo n.º 1
0
bool am_load_config() {
    free_config();
    am_engine *eng = am_init_engine(true, 0, NULL);
    if (eng == NULL) return false;
    // remove globals metatable, so we can set conf options as globals
    lua_getglobal(eng->L, "_G");
    lua_pushnil(eng->L);
    lua_setmetatable(eng->L, -2);
    lua_pop(eng->L, 1);
    int len;
    char *errmsg;
    void *data = am_read_resource("conf.lua", &len, &errmsg);
    if (data == NULL) {
        // assume conf.lua doesn't exist
        free(errmsg);
    } else {
        bool res = am_run_script(eng->L, (char*)data, len, "conf.lua");
        free(data);
        if (!res) {
            return false;
        }
    }
    read_string_setting(eng->L, "title", &am_conf_app_title, "Untitled");
    read_string_setting(eng->L, "shortname", &am_conf_app_shortname, am_conf_app_title);
    read_string_setting(eng->L, "org", &am_conf_app_org, "Unknown");
    read_string_setting(eng->L, "appid", &am_conf_app_id, "null");
    read_string_setting(eng->L, "version", &am_conf_app_version, "0.0.0");
    am_destroy_engine(eng);
    return true;
}
Exemplo n.º 2
0
bool am_load_config() {
    free_config();
    am_engine *eng = am_init_engine(true, 0, NULL);
    if (eng == NULL) return false;
    // remove globals metatable, so we can set conf options as globals
    lua_getglobal(eng->L, "_G");
    lua_pushnil(eng->L);
    lua_setmetatable(eng->L, -2);
    lua_pop(eng->L, 1);
    int len;
    char *errmsg;
    void *data = am_read_resource("conf.lua", &len, &errmsg);
    if (data == NULL) {
        // assume conf.lua doesn't exist
        free(errmsg);
    } else {
        bool res = am_run_script(eng->L, (char*)data, len, "conf.lua");
        free(data);
        if (!res) {
            am_destroy_engine(eng);
            return false;
        }
    }
    read_string_setting(eng->L, "title", &am_conf_app_title, "Untitled");
    read_string_setting(eng->L, "author", &am_conf_app_author, "Unknown");
    read_string_setting(eng->L, "shortname", &am_conf_app_shortname, am_conf_app_title);
    read_string_setting(eng->L, "appid", &am_conf_app_id, "null");
    read_string_setting(eng->L, "version", &am_conf_app_version, "0.0.0");
    read_string_setting(eng->L, "display_name", &am_conf_app_display_name, am_conf_app_title);
    read_string_setting(eng->L, "dev_region", &am_conf_app_dev_region, "en");
    read_string_setting(eng->L, "supported_languages", &am_conf_app_supported_languages, "en");
    const char *orientation_str = NULL;
    read_string_setting(eng->L, "orientation", &orientation_str, "any");
    if (strcmp(orientation_str, "any") == 0) {
        am_conf_app_display_orientation = AM_DISPLAY_ORIENTATION_ANY;
    } else if (strcmp(orientation_str, "portrait") == 0) {
        am_conf_app_display_orientation = AM_DISPLAY_ORIENTATION_PORTRAIT;
    } else if (strcmp(orientation_str, "landscape") == 0) {
        am_conf_app_display_orientation = AM_DISPLAY_ORIENTATION_LANDSCAPE;
    } else {
        fprintf(stderr, "Invalid orientation in conf.lua: %s\n", orientation_str);
        am_destroy_engine(eng);
        return false;
    }
    read_string_setting(eng->L, "icon", &am_conf_app_icon, NULL);
    read_string_setting(eng->L, "launch_image", &am_conf_app_launch_image, NULL);
    am_destroy_engine(eng);
    return true;
}