[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Please comment on these Lua to C library bindings that I wrote
- From: "Richard W.M. Jones" <rjones@...>
- Date: Tue, 20 Nov 2012 09:01:59 +0000
My bindings:
http://oirase.annexia.org/tmp/lua-guestfs.c.txt
There are some examples of using them here:
http://libguestfs.org/guestfs-lua.3.html
https://github.com/libguestfs/libguestfs/tree/master/lua/tests
The bindings are generated by a custom script, hence their length.
You can ignore everything between 'lua_guestfs_add_cdrom' and
'lua_guestfs_zgrepi', which is about 90% of the file, on a first pass.
In general, it all seems to work.
However I've had some specific problems:
- How do you pass and return 64 bit ints? (which must work with full
64 bit precision even on 32 bit platforms)
- Is the way I've done callbacks safe? Particularly stashing the
lua_State pointer in a C struct for potentially a long time.
[see lua_guestfs_set_event_callback, event_callback_wrapper]
- How do I push a userdata onto the Lua stack? Instead I'm pushing
a pointer to a userdata using: lua_pushlightuserdata (L, u);
[see event_callback_wrapper]
- How do you print "any" type, from C?
- This works:
luaL_register (L, NULL, handle_methods);
but this fails:
luaL_register (L, "guestfs", handle_methods);
Why?
- Are the bindings GC-safe? For example, I often get strings, arrays
of strings using 'luaL_checkstring', and I'm doing stack operations
at the same time. Could the strings get moved (or freed) between me
getting the pointer and me passing the pointer to the C function?
[see get_string_list for one example]
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org