Exemplo n.º 1
0
/** Set various plot graph properties.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 * \luastack
 * \lvalue A widget.
 * \lparam A plot name.
 * \lparam A table with various properties set.
 */
static int
luaA_graph_plot_properties_set(lua_State *L)
{
    widget_t *widget = luaA_checkudata(L, 1, &widget_class);
    graph_data_t *d = widget->data;
    float max_value;
    const char *title, *buf;
    size_t len;
    plot_t *plot = NULL;
    color_init_cookie_t reqs[3];
    int i, reqs_nbr = -1;

    title = luaL_checkstring(L, 2);
    luaA_checktable(L, 3);

    plot = graph_plot_get(d, title);

    if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
        reqs[++reqs_nbr] = color_init_unchecked(&plot->color_start, buf, len);

    if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len)))
        reqs[++reqs_nbr] = color_init_unchecked(&plot->pcolor_center, buf, len);

    if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len)))
        reqs[++reqs_nbr] = color_init_unchecked(&plot->pcolor_end, buf, len);

    plot->vertical_gradient = luaA_getopt_boolean(L, 3, "vertical_gradient", plot->vertical_gradient);
    plot->scale = luaA_getopt_boolean(L, 3, "scale", plot->scale);

    max_value = luaA_getopt_number(L, 3, "max_value", plot->max_value);
    if(max_value != plot->max_value)
        plot->max_value = plot->current_max = max_value;

    if((buf = luaA_getopt_lstring(L, 3, "style", NULL, &len)))
        switch (a_tokenize(buf, len))
        {
        case A_TK_BOTTOM:
            plot->draw_style = Bottom_Style;
            break;
        case A_TK_LINE:
            plot->draw_style = Line_Style;
            break;
        case A_TK_TOP:
            plot->draw_style = Top_Style;
            break;
        default:
            break;
        }

    for(i = 0; i <= reqs_nbr; i++)
        color_init_reply(reqs[i]);

    widget_invalidate_bywidget(widget);

    return 0;
}
Exemplo n.º 2
0
Arquivo: tag.c Projeto: kanru/awesome
/** Create a new tag.
 * \param L The Lua VM state.
 *
 * \luastack
 * \lparam A table with at least a name attribute.
 * Optional attributes are: mwfact, ncol, nmaster and layout.
 * \lreturn A new tag object.
 */
static int
luaA_tag_new(lua_State *L)
{
    size_t len;
    tag_t *tag;
    int ncol, nmaster;
    const char *name, *lay;
    double mwfact;
    layout_t *layout;

    luaA_checktable(L, 2);

    if(!(name = luaA_getopt_lstring(L, 2, "name", NULL, &len)))
        luaL_error(L, "object tag must have a name");

    mwfact = luaA_getopt_number(L, 2, "mwfact", 0.5);
    ncol = luaA_getopt_number(L, 2, "ncol", 1);
    nmaster = luaA_getopt_number(L, 2, "nmaster", 1);
    lay = luaA_getopt_string(L, 2, "layout", "tile");

    layout = name_func_lookup(lay, LayoutList);

    tag = tag_new(name, len,
                  layout,
                  mwfact, nmaster, ncol);

    return luaA_tag_userdata_new(L, tag);
}