lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Asko Kauppi wrote:

Thanks for the heads up.


Thanks. I was resisted to adapt 2.8.x (all new Cairo functions got "not implemented!" status). But at least we can have fixes for old functions.


Would you consider adopting an object-like interface, instead of the C-like you currently use? This is the #1 issue keeping me away from LuaCairo and using others (oocairo).

The Cairo C++ API (cairomm) could be used as a reference API. It is as official as the C API is.

Your current sample (now and "then"):
[oo example snipped]

I tried to hack my code to add an oo style. It seems work. But before to work for complete implementation, I need your advice: Do you see any logic error in the following solution?


cr = cairo.create(cs)   -- creates a cairo_t* lightuserdata
-- Current style
cairo.save(cr)
-- OO style
ctx = cairo.Context(cr) -- creates a Context userdata
ctx:save()

They are implemented as:

static int l_cairo_save(lua_State* L)
{
    cairo_t *cr = (cairo_t *) check_lightuserdata(L, 1);
    cairo_save(cr);
    return 0;
}

static int ool_cairo_save(lua_State* L)
{
    replace_context_with_cairo_t (L);
    return l_cairo_save(L);
}

static void replace_context_with_cairo_t (lua_State *L)
{
    Context *o = check_contextud(L, 1);  // o  ...
    lua_pushlightuserdata(L, o->cr_);    // o  ... cr
    lua_replace(L, 1);                   // cr ...
}

Ie. if a Cairo API function has cairo_t* as first parameter then;
-- put it in Context userdata's API
-- when called, forward it to existing l_xxx() brother.

Is it logical or am I hallucinating :)


--
Regards,
Hakki Dogusan