View Single Post
Old 11-01-2009, 08:43 AM   #9
Iņigo
Guru
Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.Iņigo did not drink the Kool Aid.
 
Posts: 730
Karma: 72743
Join Date: Feb 2008
Location: Here or there
Device: iRex iLiad, iRex DR800S. K4NT. Kobo Aura, Aura One, Libra 2.
Quote:
Originally Posted by ericshliao View Post
Iņigo,
I see that there is a line in your code:
evbox:modify_bg(gtk.STATE_NORMAL, gdk.color_parse("black"))

Are you sure "gdk.color_parse("black")" correct? By the ref (http://library.gnome.org/devel/gdk/2...nd-Colors.html), gdk_color_parse() does not return a GdkColor variable.

Gdk and Pango have some structs without a function to create it. For example, GdkColor, PangoMatrix. I can create these structs in C code without a creating-function, but I don't know how to create them in Lua. It is really frustrating.
It works so it has must return a GdkColor

Code:
[inigo@inigo ~]$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require("lgob.gdk")
> =gdk.color_parse("black")
Boxed(GdkColor): 0x23ddbb0
In my experience, the Lua API is not exactly the same as the C API, sometimes you should expect the value you want in a var argument you pass to the function to be filled (like in C) but often you get it as the return value.

I think is this second case in gdk.color_parse(), the color is returned:

Code:
Lua:
    color = gdk.color_parse("black")
C:
    GdkColor *col = gdk_colormap_alloc_color();
    gdk_color_parse("black", col);
I spent some hours yesterday fighting with TreeView Iters... (well, and with pixbufs inside a treeview, but that's another story...)

[I needed the iter for a row in a treeview when I click on it]
Code:
local res, iterpath = view:get_path_at_pos(x, y)
local iter = gtk.TreeIter.new()
model:get_iter_from_string(iter, iterpath)
Here I first have to create an "iter", and then "model:get_iter_from_string()" method fills that iter with the value I want. Similar to C API.

But note that in previous "view:get_path_at_pos()" call the path I want is returned as the second value, first one being a true/false boolean saying if method was ok. Completely different from C API.

Coming from pygtk I find Lua API quite confusing, sometimes it's like C API but other times is like Python API. It's not predictive or at least I can't fully understand the logic behind it.

As there is no lgob documentation I often spend hours and hours trying to get the proper API for some functions and methods... read C and python API, look for some examples in google, check different approaches and use prints to check the results...

Anyway, coding in lua/lgob is funny, not so funny as in pygtk but much better than in C

Iņigo
Iņigo is offline   Reply With Quote