lua-users home
lua-l archive

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


I am starting to use Lua as scripting engine for a Claws Mail plugin.
While I was able to create something basically working quite easily in
short time, there are some troubles I found no solution for, yet.

Some background - why?

I am long time Claws Mail user. At some point I started to use Python
plugin for some tasks, which worked to my satisfaction.

World did not stop turning, Python 2 is being replaced with Python 3.
Current Claws Mail is GTK2 based which basically means Python 2 with
PyGTK binding... and it does not work in current FreeBSD ports
framework, there is no port actually for the plugin.

I tried development version of Claws Mail with GTK3 which has Python
plugin ported to Python 3, but this require other GTK binding for which
there is no FreeBSD port. Also this new version is not yet fully
polished, there are some small issues.

Then I decided to try something new. It was possible to create new
plugin, I did manage to put some patches together to hook everything
into build process and it basically works.

The problem - what?

In Claws Mail there are some places where it is possible to execute
external scripts. With scripting plugin one can use some script invoked
when mail compose windows is opened or when a button in toolbar is
pressed, or when some action in menu is selected.

Currently I know no way how can I differentiate which compose window my
script is being called from in case of multiple windows being open.
Basically everything ends up with question how can I call a Lua script
with an argument.

How it works, now?

When plugin is being loaded, a function is registered with Claws Mail
hook mechanism which is to be called on creating mail compose window.
When I try to create new message or reply to existing one, compose
window is being created and my function is being called with an
argument - C pointer to structure describing the window. In my C
function I use luaL_dofile() to load a script from file and execute it.

And here comes the question - how can I use this C pointer as an
argument for my script? I know I can do

lua_pushlightuserdata(L,(void *)compose_window_argument);

but I found no way to access this argument from my_script_file. As an
ugly workaround, not working properly with more than one opened window
at the same time, I use


where in set_compose_window I just store argument given to some static
variable which I then access with function

static int _get_compose_self(lua_State *L)
 lua_pushlightuserdata(L,(void *)compose);
 return 1;

called from Lua side as

local compose = compose_window.get()

This works with script being called on windows create, but in case of
an action executed via some menu item or toolbar button value got this
way is not necessarily correct.

Could somebody help me with this issue? Is it possible to do it with
push/dofile/pop sequence as outlined above?