<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>
        jd:/dev/blog    </title>
        <link href="http://julien.danjou.info/blog/index.xml" rel="self" />
    
        <link href="http://julien.danjou.info/blog/"/>
    
        
    <updated>2012-01-03T17:49:33Z</updated>

    <id>http://julien.danjou.info/blog/index.xml</id>

            <entry>
            <title type="html">Google Calendar notifications using pynotify</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2012/google-calendar-pynotify"/>
            <updated>2012-01-03T18:55:00Z</updated>
            <published>2012-01-03T18:55:00Z</published>
            <id>/blog/2012/google-calendar-pynotify</id>
                        <category   scheme="/blog/tags"
                        term="python"
                        label="Python" />
                        <category   scheme="/blog/tags"
                        term="gtk"
                        label="Gtk" />
                        <category   scheme="/blog/tags"
                        term="notify"
                        label="Notify" />
                        <category   scheme="/blog/tags"
                        term="googlecalendar"
                        label="Googlecalendar" />
                        <category   scheme="/blog/tags"
                        term="gdata"
                        label="Gdata" />
            
            <content type="html">
                                  &lt;p&gt;I use &lt;a href=&#34;http://google.com/calendar&#34;&gt;Google Calendar&lt;/a&gt; to manage my calendars,
and I really missed something to warn me whenever I have an appointment with
an alert set.&lt;/p&gt;
&lt;p&gt;So here is an example of a Python program to do such a thing. It is written using
the &lt;a href=&#34;http://code.google.com/p/gdata-python-client/&#34;&gt;Google Data APIs Python client library&lt;/a&gt;
and pynotify.&lt;/p&gt;
&lt;p&gt;I&#39;ll detail the code here, so you can build your own and adapt it to your needs.&lt;/p&gt;
&lt;p&gt;First, we need to import GTK+ and pynotify, and initialize it.&lt;/p&gt;
&lt;pre class=&#34;prettyprint python&#34;&gt;
import gtk
import pynotify
pynotify.init(sys.argv[0])
&lt;/pre&gt;

&lt;p&gt;Then, we need to import gdata Calendar API and connect to the calendar. I&#39;ll
use the simple email/password way to login, which is clearly not the best,
but it&#39;s also the simplest. Feel free to use OAuth 2.0. :-)&lt;/p&gt;
&lt;pre class=&#34;prettyprint python&#34;&gt;
calendar_service = gdata.calendar.service.CalendarService()
calendar_service.email = &#39;mygooglelogin&#39;
calendar_service.password = &#39;mygooglepassword&#39;
calendar_service.ProgrammaticLogin()
&lt;/pre&gt;

&lt;p&gt;Now we&#39;re ready to request stuff and notify! First, request the events from
the default calendar.&lt;/p&gt;
&lt;pre class=&#34;prettyprint python&#34;&gt;
feed = calendar_service.GetCalendarEventFeed()
&lt;/pre&gt;

&lt;p&gt;Now we can iterate over &lt;em&gt;feed&lt;/em&gt; and do various checks.&lt;/p&gt;
&lt;pre class=&#34;prettyprint python&#34;&gt;
for event in feed.entry:
    # If the event status is not confirmed, go to the next event.
    if event.event_status.value != &#34;CONFIRMED&#34;:
        continue
    # Now iterate over all the event dates (usually it has one)
    for when in event.when:
        # Parse start and end time
        try:
            start_time = datetime.datetime.strptime(when.start_time.split(&#34;.&#34;)[0], &#34;%Y-%m-%dT%H:%M:%S&#34;)
            end_time = datetime.datetime.strptime(when.end_time.split(&#34;.&#34;)[0], &#34;%Y-%m-%dT%H:%M:%S&#34;)
        except ValueError:
            # ValueError happens on parsing error. Parsing errors
            # usually happen for &#34;all day&#34; events since they have
            # not time, but we do not care about this events.
            continue
        now = datetime.datetime.now()
        # Check that the event hasn&#39;t already ended
        if end_time &gt; now:
            # Check each alert
            for reminder in when.reminder:
                # We handle only reminders with method &#34;alert&#34;
                # and whose start time minus the reminder delay has passed
                if reminder.method == &#34;alert&#34; \
                        and start_time - datetime.timedelta(0, 60 * int(reminder.minutes)) &lt; now:
                    # Build the notification
                    notification = pynotify.Notification(summary=event.title.text,
                                                         message=event.content.text)
                    # Set an icon from the GTK+ stock icons
                    notification.set_icon_from_pixbuf(gtk.Label().render_icon(gtk.STOCK_DIALOG_INFO,
                                                                              gtk.ICON_SIZE_LARGE_TOOLBAR))
                    notification.set_timeout(0)
                    # Show the notification
                    notification.show()
&lt;/pre&gt;

&lt;p&gt;Running this program, you should see a notification if an appointment has an
alert to be raised at that time.&lt;/p&gt;
&lt;p&gt;This should be enough to start to build something.&lt;/p&gt;
&lt;p&gt;If you don&#39;t want to program this into Python, you might want to take a look
at &lt;a href=&#34;http://code.google.com/p/gcalcli/wiki/HowTo&#34;&gt;gcalcli&lt;/a&gt;.&lt;/p&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">Using GTK+ stock icons with pynotify</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/python-notify-with-gtk-stock-icon"/>
            <updated>2011-12-27T11:55:00Z</updated>
            <published>2011-12-27T11:55:00Z</published>
            <id>/blog/2011/python-notify-with-gtk-stock-icon</id>
                        <category   scheme="/blog/tags"
                        term="python"
                        label="Python" />
                        <category   scheme="/blog/tags"
                        term="gtk"
                        label="Gtk" />
                        <category   scheme="/blog/tags"
                        term="notify"
                        label="Notify" />
            
            <content type="html">
                                  &lt;p&gt;It took me a while to find this, so I&#39;m just blogging it so other people
will be able to find it.&lt;/p&gt;
&lt;p&gt;I wanted to send a &lt;a href=&#34;http://www.galago-project.org/specs/notification/&#34;&gt;desktop
notification&lt;/a&gt; using
pynotify, but using a &lt;a href=&#34;http://developer.gnome.org/gtk/2.24/gtk-Stock-Items.html&#34;&gt;GTK+ stock
icons&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;With the following snippet, I managed to do it.&lt;/p&gt;
&lt;pre class=&#34;prettyprint&#34;&gt;
import pynotify
pynotify.init(&#34;myapp&#34;)
import gtk
n = pynotify.Notification(summary=&#34;Summary&#34;, message=&#34;Message!&#34;)
n.set_icon_from_pixbuf(gtk.Label().render_icon(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_LARGE_TOOLBAR))
n.show()
&lt;/pre&gt;

&lt;p&gt;Note that the use of a &lt;em&gt;Label&lt;/em&gt; is just to have a widget instanciated to use
the &lt;em&gt;render_icon()&lt;/em&gt; method. It could be any widget type as far as I
understand.&lt;/p&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">My OpenStack work</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/my-openstack-work"/>
            <updated>2011-12-16T17:34:00Z</updated>
            <published>2011-12-16T17:34:00Z</published>
            <id>/blog/2011/my-openstack-work</id>
                        <category   scheme="/blog/tags"
                        term="openstack"
                        label="Openstack" />
                        <category   scheme="/blog/tags"
                        term="debian"
                        label="Debian" />
            
            <content type="html">
                                  &lt;p&gt;Like I already wrote here last week, I&#39;ve been heavily working on
&lt;a href=&#34;http://openstack.org&#34;&gt;OpenStack&lt;/a&gt; for the last weeks.&lt;/p&gt;
&lt;p&gt;My first assignment was to package OpenStack for Debian. The packages
already present in unstable were mainly done by &lt;a href=&#34;http://thomas.goirand.fr/&#34;&gt;Thomas
Goirand&lt;/a&gt;, who based its work on the one done in
&lt;a href=&#34;http://ubuntu.com&#34;&gt;Ubuntu&lt;/a&gt;. Therefore, the packages where not in a very
good shape for Debian.&lt;/p&gt;
&lt;p&gt;Today Ghe Rivero and I (members of the &lt;a href=&#34;https://alioth.debian.org/projects/openstack&#34;&gt;OpenStack Debian packaging
team&lt;/a&gt;) managed to push the
&lt;a href=&#34;https://launchpad.net/openstack/+milestone/essex-2&#34;&gt;OpenStack Essex 2
milestone&lt;/a&gt; into unstable
with great success. You can now test and deploy OpenStack Essex 2 very easily!&lt;/p&gt;
&lt;p&gt;Packaging OpenStack &lt;a href=&#34;https://review.openstack.org/#dashboard,1669&#34;&gt;made me write several
patches&lt;/a&gt;, mainly related to
packaging, patches which were all accepted and merged by upstream. This is
nice because most of the OpenStack Debian packages lost their
&lt;em&gt;debian/patches&lt;/em&gt; directories now!&lt;/p&gt;
&lt;p&gt;Finally, I&#39;ve finished to implement one blueprint I really missed: the
&lt;a href=&#34;https://blueprints.launchpad.net/nova/+spec/support-kvm-boot-from-iso&#34;&gt;ability to boot from an ISO
image&lt;/a&gt;
using &lt;a href=&#34;http://libvirt.org&#34;&gt;libvirt&lt;/a&gt;. The code still needs a review, but it
should be included in the Essex 3 milestone if everything&#39;s right.&lt;/p&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">New job, new blog</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/new-job-new-blog"/>
            <updated>2011-12-07T13:47:00Z</updated>
            <published>2011-12-07T13:47:00Z</published>
            <id>/blog/2011/new-job-new-blog</id>
                        <category   scheme="/blog/tags"
                        term="work"
                        label="Work" />
                        <category   scheme="/blog/tags"
                        term="openstack"
                        label="Openstack" />
                        <category   scheme="/blog/tags"
                        term="python"
                        label="Python" />
                        <category   scheme="/blog/tags"
                        term="debian"
                        label="Debian" />
            
            <content type="html">
                                  &lt;p&gt;It has been a while since I blogged but I&#39;ve been very busy, with my new job and this new blog!&lt;/p&gt;
&lt;h1&gt;New job!&lt;/h1&gt;
&lt;p&gt;I quitted my job last September, and found another one that I started in
October. I&#39;m now the lead developer of &lt;a href=&#34;http://www.enovance.com/fr/produits-solutions/opencloud-opensource/enovance-labs&#34;&gt;eNovance
Labs&lt;/a&gt;,
where I work on the &lt;a href=&#34;http://openstack.org/&#34;&gt;OpenStack&lt;/a&gt; project. So far, this allowed me to contribute heavily to the &lt;a href=&#34;https://alioth.debian.org/projects/openstack&#34;&gt;Debian packaging of OpenStack&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;New blog!&lt;/h1&gt;
&lt;p&gt;In the meantime, I took some time to redesign my personal homepage and this
blog, which is now using &lt;a href=&#34;https://github.com/hyde/hyde&#34;&gt;Hyde&lt;/a&gt;, the
&lt;a href=&#34;http://python.org&#34;&gt;Python&lt;/a&gt; equivalent of &lt;a href=&#34;http://jekyllrb.com/&#34;&gt;Jekyll&lt;/a&gt;,
which is in &lt;a href=&#34;http://www.ruby-lang.org/&#34;&gt;Ruby&lt;/a&gt;. Since I dislike Ruby
(sorry), I preferred to use a Python based generator, and I admit Hyde is really
cool.
Since I really suck at Web design, this one is obviously based on &lt;a href=&#34;http://twitter.github.com/bootstrap/&#34;&gt;Twitter&#39;s bootstrap&lt;/a&gt;&lt;/p&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">Google Contacts for Emacs</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/google-contacts-for-emacs"/>
            <updated>2011-09-26T13:01:00Z</updated>
            <published>2011-09-26T13:01:00Z</published>
            <id>/blog/2011/google-contacts-for-emacs</id>
                        <category   scheme="/blog/tags"
                        term="googlecontacts"
                        label="Googlecontacts" />
                        <category   scheme="/blog/tags"
                        term="emacs"
                        label="Emacs" />
            
            <content type="html">
                                  &lt;p&gt;I finally finished a thing I was really missing: accessing my Google
Contacts from Emacs.&lt;/p&gt;
&lt;p&gt;That&#39;s now possible, thanks to my new
&lt;a href=&#34;/software/google-contacts.el&#34;&gt;google-contacts.el&lt;/a&gt;
package.&lt;/p&gt;
&lt;p&gt;&lt;video controls=&#34;controls&#34;&gt;
&lt;source src=&#34;http://julien.danjou.info/images/emacs-google-contacts.ogv&#34; type=&#34;video/ogg&#34; /&gt;
&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;It includes searching for any contact and displaying the result in a window.
You can also jump to a contact from &lt;a href=&#34;http://gnus.org&#34;&gt;Gnus&lt;/a&gt; by pressing a
key, and complete e-mail addresses while composing a mail.&lt;/p&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">OAuth 2.0 for Emacs</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/oauth-2.0-for-emacs"/>
            <updated>2011-09-23T18:01:00Z</updated>
            <published>2011-09-23T18:01:00Z</published>
            <id>/blog/2011/oauth-2.0-for-emacs</id>
                        <category   scheme="/blog/tags"
                        term="oauth"
                        label="Oauth" />
                        <category   scheme="/blog/tags"
                        term="emacs"
                        label="Emacs" />
            
            <content type="html">
                                  &lt;p&gt;This week, I&#39;ve finished my &lt;a href=&#34;http://oauth.net/2/&#34;&gt;OAuth 2.0&lt;/a&gt;
client implementation for &lt;a href=&#34;http://www.gnu.org/software/emacs/&#34;&gt;GNU Emacs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I have &lt;a href=&#34;http://bzr.savannah.gnu.org/lh/emacs/elpa/revision/126?start_revid=126&#34;&gt;imported it&lt;/a&gt;
into &lt;a href=&#34;http://elpa.gnu.org/&#34;&gt;GNU ELPA&lt;/a&gt; so Emacs 24 users will be soon able to
install it using the new Emacs packaging system.&lt;/p&gt;
&lt;p&gt;OAuth 2.0 can be used to access, among others,
&lt;a href=&#34;http://code.google.com/apis/accounts/docs/OAuth2.html&#34;&gt;Google APIs&lt;/a&gt; or the
&lt;a href=&#34;http://developers.facebook.com/docs/authentication/&#34;&gt;Facebook Graph API&lt;/a&gt;.&lt;/p&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">Quitting my job</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/quitting-my-job"/>
            <updated>2011-08-29T10:57:00Z</updated>
            <published>2011-08-29T10:57:00Z</published>
            <id>/blog/2011/quitting-my-job</id>
                        <category   scheme="/blog/tags"
                        term="work"
                        label="Work" />
            
            <content type="html">
                                  &lt;p&gt;After more than 5 years at &lt;a href=&#34;http://www.easter-eggs.com&#34;&gt;Easter-eggs&lt;/a&gt; as a
system engineer, I&#39;ll be leaving my job soon.&lt;/p&gt;
&lt;p&gt;It has been a fabulous adventure, also due to the &#34;cooperative&#34; nature of
the company. I&#39;ve enjoyed worked here, with great people. I do wish them
luck for the future. Looking at the numerous things I did for the past
years, it has been quite productive!&lt;/p&gt;
&lt;p&gt;Therefore, I&#39;ll be looking for a new job in the next weeks, which will
probably keep me busy a bit. :-)&lt;/p&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">Python sets comparisons</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/python-sets-comparisons"/>
            <updated>2011-05-17T14:01:00Z</updated>
            <published>2011-05-17T14:01:00Z</published>
            <id>/blog/2011/python-sets-comparisons</id>
                        <category   scheme="/blog/tags"
                        term="python"
                        label="Python" />
            
            <content type="html">
                                  &lt;p&gt;This week I lost some time playing with &lt;a href=&#34;http://python.org&#34;&gt;Python&lt;/a&gt;&#39;s
&lt;a href=&#34;http://docs.python.org/library/stdtypes.html#set&#34;&gt;sets&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After digging into
Python source code, I finally discovered there is what seems to be little
bug. Anyway, it has been &#34;fixed&#34; in Python 3, fortunately. I did not find if
it was reported somewhere, but since it&#39;s fixed, it&#39;s not a big deal.&lt;/p&gt;
&lt;pre class=&#34;prettyprint&#34;&gt;
Python 2.7.1+ (default, Apr 20 2011, 10:53:33) 
[GCC 4.5.2] on linux2
Type &#34;help&#34;, &#34;copyright&#34;, &#34;credits&#34; or &#34;license&#34; for more information.
&gt;&gt;&gt; class A(object):
...     def __eq__(self, other):
...             return True
... 
&gt;&gt;&gt; A() == A()
True
&gt;&gt;&gt; [A()] == [A()]
True
&gt;&gt;&gt; set([A()]) == set([A()])
False
&lt;/pre&gt;

&lt;p&gt;This clearly did not make any sense to me. I&#39;ve then tested under
Python 3.2:&lt;/p&gt;
&lt;pre class=&#34;prettyprint&#34;&gt;
Python 3.2.1a0 (default, May  4 2011, 19:59:25) 
[GCC 4.6.1 20110428 (prerelease)] on linux2
Type &#34;help&#34;, &#34;copyright&#34;, &#34;credits&#34; or &#34;license&#34; for more information.
&gt;&gt;&gt; class A(object):
...     def __eq__(self, other):
...             return True
... 
&gt;&gt;&gt; set([A()]) == set([A()])
Traceback (most recent call last):
  File &#34;&lt;stdin&gt;&#34;, line 1, in &lt;module&gt;
TypeError: unhashable type: &#39;A&#39;
&lt;/pre&gt;

&lt;p&gt;At least, raising an error is saner. It actually helped me to understand
what I needed to do to have my sets working correctly with Python 2:&lt;/p&gt;
&lt;pre class=&#34;prettyprint&#34;&gt;
Python 2.7.1+ (default, Apr 20 2011, 10:53:33) 
[GCC 4.5.2] on linux2
Type &#34;help&#34;, &#34;copyright&#34;, &#34;credits&#34; or &#34;license&#34; for more information.
&gt;&gt;&gt; class A(object):
...     def __eq__(self, other):
...             return True
...     def __hash__(self):
...             return 123456789
... 
&gt;&gt;&gt; set([A()]) == set([A()])
True
&lt;/pre&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">Why not Lua</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/why-not-lua"/>
            <updated>2011-04-26T18:53:00Z</updated>
            <published>2011-04-26T18:53:00Z</published>
            <id>/blog/2011/why-not-lua</id>
                        <category   scheme="/blog/tags"
                        term="lua"
                        label="Lua" />
            
            <content type="html">
                                  &lt;p&gt;Since my latest announcement of the &lt;a href=&#34;/blog/2011/lua-workshop-at-Fabelier-tmplab&#34;&gt;Lua workshop&lt;/a&gt;, I received a couple of
emails asking why I discourage the use of &lt;a href=&#34;http://lua.org&#34;&gt;Lua&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Actually, I already wrote out many of &lt;a href=&#34;/blog/2008/rants-about-lua&#34;&gt;the things I dislike about Lua&lt;/a&gt;. I
won&#39;t come back on this technical issues here, but since Lua 5.2 is not yet
released (it&#39;s still at alpha stage), they are still relevant nowadays.&lt;/p&gt;
&lt;h1&gt;Stack based API is harder&lt;/h1&gt;
&lt;p&gt;The ease of integration of Lua into a C program is one of the point of Lua.
They claim it&#39;s very easy to integrate Lua into your C application, because
it does not use pointer, nor reference counting, nor anything that requires
a minimum amount of skills to be used.&lt;/p&gt;
&lt;p&gt;It uses a virtual stack based approach. You push or pop things on a stack,
and refers to them using a relative or absolute index.&lt;/p&gt;
&lt;p&gt;In order to people who never wrote Lua code to understand, here&#39;s a quick
example on how this work. The &lt;em&gt;L&lt;/em&gt; pointer is a Lua environment.&lt;/p&gt;
&lt;pre class=&#34;prettyprint lang-c&#34;&gt;
/* Create a table on the stack: index 1 */
lua_newtable(L);
/* Push a string on the stack: index 2 */
lua_pushstring(L, &#34;hello&#34;);
/* Push a number on the stack: index 3 */
lua_pushnumber(L, 123);
/* Set newtable[&#34;hello&#34;] = 123 */
lua_settable(L, -3);
&lt;/pre&gt;

&lt;p&gt;You first push a table (in Lua, a table is almost equivalent to what you&#39;d
call a hash table in other language), then push the key, the value, and do
the assignment operation. In the settable, we use -3 as index, meaning the
&#34;3rd item on the stack counting from top&#34;. We could also have written
&lt;em&gt;lua_settable(L, 1)&lt;/em&gt;, since the table is also the first item on the stack from
the bottom.&lt;/p&gt;
&lt;p&gt;So far, so good.&lt;/p&gt;
&lt;p&gt;Problems arise when you do more complicated stuff. My previous example is
what you would typically find in a tutorial, but of course, real life is
different, and usually more complex. If you cut the things in different
parts, it can start to be more complicated.&lt;/p&gt;
&lt;p&gt;Let&#39;s take a look at the following:&lt;/p&gt;
&lt;pre class=&#34;prettyprint lang-c&#34;&gt;
/* Create a table on the stack: index 1 */
lua_newtable(L);
/* Push a string on the stack: index 2 */
lua_pushstring(L, &#34;hello&#34;);
/* Push a number on the stack: index 3 */
lua_pushnumbe(L, mycomputingfunction());
/* Set newtable[&#34;hello&#34;] = 123 */
lua_settable(L, -3);
&lt;/pre&gt;

&lt;p&gt;Here, we do exactly the same thing, but we do not push &lt;em&gt;123&lt;/em&gt; directly: we
compute it.&lt;/p&gt;
&lt;p&gt;And here&#39;s the trick: if your computing function is also using the Lua
stack, things can become &lt;em&gt;very&lt;/em&gt; messy. As long as your computing function use
the stack cleanly by pushing and poping all its item, and returning the
stack &lt;strong&gt;in the same state it was before&lt;/strong&gt;, you&#39;re safe. The problem is that in a
complex program, you also write bugs. You do not chose to, but you do. And
sometimes, you forget to pop one of the item you fetched from a table.&lt;/p&gt;
&lt;p&gt;Imagine that &lt;em&gt;mycomputingfunction&lt;/em&gt; is:&lt;/p&gt;
&lt;pre class=&#34;prettyprint lang-c&#34;&gt;
int
mycomputingfunctiong(void)
{
  /* Just push the table we want to fetch
     the number from on the stack */
  pushatableonstack(L);
  lua_pushstring(L, &#34;mykey&#34;);
  lua_gettable(L, -2);
  return lua_tonumber(L, -1);
}
&lt;/pre&gt;

&lt;p&gt;This function works perfectly. It pushes a table, then a key (&lt;em&gt;&#34;mykey&#34;&lt;/em&gt;), then
fetches mytable[&#34;mykey&#34;] and pops the key (lua_gettable does push value/pop
key itself), and then returns the numeric value of the last item (the
fetched one) of the stack.&lt;/p&gt;
&lt;p&gt;However, this function has a bug: it does not pop the table! This does not
prevent the function to work. It does not raise a segmentation fault. It
does not show any problem under &lt;a href=&#34;http://www.gnu.org/software/gdb/&#34;&gt;gdb&lt;/a&gt;. It does not show any leak under
&lt;a href=&#34;http://valgrind.org/&#34;&gt;Valgrind&lt;/a&gt;. It does now show any problem under &lt;strong&gt;any standard C debugging tool&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;But when you&#39;ll start using it, your program will start to do weird things,
and you&#39;ll have to spend a huge amount of time debugging it manually,
dumping the stack content at each step of your program to watch out what&#39;s
wrong.&lt;/p&gt;
&lt;p&gt;Another bad thing, that can happen, is some code poping accidentally an item
from the stack, or worst, from an empty stack. This does not raise any error
on the Lua side, but will break your program in very unfunny way.&lt;/p&gt;
&lt;p&gt;Even if I&#39;ve been very meticulous writing &lt;a href=&#34;http://awesome.naquadah.org&#34;&gt;awesome&lt;/a&gt;, but we hit that problem
regularly.&lt;/p&gt;
&lt;p&gt;The easiest workaround is to use &lt;em&gt;lua_settop(L, 0)&lt;/em&gt; to reset the stack to 0
element. Doing this regularly (like after each program event or treatment)
can remove left-over items and avoid the never ending stack grow you may
experience if your left-over items continue to pile up. Did I tell you I
dislike work-around?&lt;/p&gt;
&lt;p&gt;You could also use &lt;em&gt;lua_call()&lt;/em&gt;, which would avoid such an error, but this
would require a huge amount of indirection, and would make write more
(useless) code.&lt;/p&gt;
&lt;p&gt;This kind of problem does not exists with pointer based API. If you screw
things up, the problem will cause a segmentation fault or leak memory, or
cause things you can (easily) debug with standard tools like gdb or
Valgrind.&lt;/p&gt;
&lt;h1&gt;No reference counting is a pain in the ass&lt;/h1&gt;
&lt;p&gt;Userdata objects are variable Lua size objects embedding a C struct you
define. It&#39;s the equivalent of an object in object oriented language.&lt;/p&gt;
&lt;p&gt;Lua does not provide any reference counting for the userdata objects. That
means you can push this objects on the stack, use them, but they cannot
directly reference each others. If you have a &#34;car&#34; userdata and a &#34;wheel&#34;
one, the car cannot hold directly a reference to the wheel. This is not
possible because userdata are allocated and garbage collected by Lua, and
there&#39;s no way to increase the reference counting yourself.&lt;/p&gt;
&lt;p&gt;So the common hack is to store the wheel into a table as a value, and store
the table index as an integer into the car data structure.&lt;/p&gt;
&lt;p&gt;This obviously makes memory leaks tracking harder, add huge level of
reference indirection in usage (still more code), and does not make the
whole process less error prone (at least in my opinion).&lt;/p&gt;
&lt;h1&gt;No paradigm makes you lose time&lt;/h1&gt;
&lt;p&gt;Lua is proud to come with no paradigm and to provide metatables.
&lt;a href=&#34;http://julien.danjou.info/blog/2008.html#_Rants_about_Lua&#34;&gt;I already showed 3 years ago that it has big flaws&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To me, this ain&#39;t no good. Lua is not functional, nor it is object oriented.&lt;/p&gt;
&lt;p&gt;Most people, including me, want one of this paradigm, or any else. Plain old
imperative is not enough.&lt;/p&gt;
&lt;p&gt;So you&#39;ll start to build more, or to use something like &lt;a href=&#34;http://loop.luaforge.net/&#34;&gt;LOOP&lt;/a&gt;, which
implements an object model. You&#39;ll implement your paradigm. I say life is
too short to (re)write a paradigm.&lt;/p&gt;
&lt;p&gt;In &lt;a href=&#34;http://awesome.naquadah.org&#34;&gt;awesome&lt;/a&gt; we wanted to have an object oriented approach (this is kind of
typical in such a graphical application context), so we tried to build one.
To me, this started to be a show stopper when I realized that I&#39;ve ended
writing Python object model into Lua while developing &lt;em&gt;awesome (which aims to
be a window manager, not a language)&lt;/em&gt;. This is one of the reason I stopped
hacking on Lua things.&lt;/p&gt;
&lt;p&gt;I liked Python object model and wanted to have it in Lua, and spending time
rewriting Python is just not worth it. I probably should have chose Python,
not Lua. YMMV.&lt;/p&gt;
&lt;h1&gt;Embedding may not be a good choice&lt;/h1&gt;
&lt;p&gt;This is not Lua related, but I want to mention it. Googling for
&#34;&lt;a href=&#34;http://www.google.fr/search?q=embedding+vs+extending&#34;&gt;embedding vs extending&lt;/a&gt;&#34; will probably tell you more about why you should
double check that you really need to embed Lua rather than to extend it.&lt;/p&gt;
&lt;h1&gt;Being small is not an excuse&lt;/h1&gt;
&lt;p&gt;One common argument to choose Lua is that it has a small footprint. Yeah,
that&#39;s true, but that&#39;s useless. Bummer! When I program, I don&#39;t have any
resource usage pressure. People who have such pressure are either paranoids
or playing in the world of embedded computers. This is also a no more
existing conception since quad core processors equiped phones are coming
into the market. I&#39;m rather confident that what we used to call embedded
devices are just dead and are now plain computers. But as usual, YMMV.&lt;/p&gt;
&lt;p&gt;So start to forget about it, run in your underpants and yelling &#34;yay we
killed that shit!&#34;, and then use real computers stuff. :-)&lt;/p&gt;
&lt;p&gt;Even &lt;a href=&#34;http://shootout.alioth.debian.org/u32/lua.php&#34;&gt;if benchmarks show how Lua is damn fast&lt;/a&gt;, remember what a benchmark
proves: that you can do useless things very fast.&lt;/p&gt;
&lt;h1&gt;Too few extension modules&lt;/h1&gt;
&lt;p&gt;This is not directly Lua&#39;s fault, but there&#39;s too few extension modules for
Lua. The community is quite small compared to other big languages&#39; ones.&lt;/p&gt;
&lt;h1&gt;So think twice&lt;/h1&gt;
&lt;p&gt;before you choose Lua (or any other language). My recommendations these days
would be not to embed, but to extend. If you really have no choice and need
to embed a language into your application, &lt;a href=&#34;http://www.gnu.org/s/guile/&#34;&gt;GNU Guile&lt;/a&gt; is probably worth
considering, because it&#39;s a Scheme and therefore a functional language :-),
and because it can provides also different languages.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://git.savannah.gnu.org/gitweb/?p=guile.git;a=shortlog;h=refs/heads/lua&#34;&gt;Including Lua&lt;/a&gt;.&lt;/p&gt;  
                            </content>
        </entry>
            <entry>
            <title type="html">Lua workshop at Fabelier/tmplab</title>
            <author><name>Julien Danjou</name></author>
            <link href="http://julien.danjou.info/blog/2011/lua-workshop-at-Fabelier-tmplab"/>
            <updated>2011-04-14T14:04:00Z</updated>
            <published>2011-04-14T14:04:00Z</published>
            <id>/blog/2011/lua-workshop-at-Fabelier-tmplab</id>
                        <category   scheme="/blog/tags"
                        term="lua"
                        label="Lua" />
            
            <content type="html">
                                  &lt;p&gt;It seems I&#39;ll be at the &lt;a href=&#34;http://fabelier.org/lua-programming-language-by-julien-danjou/&#34;&gt;Lua workshop at Fabelier/tmplab&lt;/a&gt; on April 28th 2011,
where I&#39;ll try to present and talk about &lt;a href=&#34;http://lua.org&#34;&gt;Lua&lt;/a&gt;, how to use it, and why you
should probably not use it. ;-)&lt;/p&gt;  
                            </content>
        </entry>
    </feed>
