diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-11-20 16:20:12 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-11-20 16:34:23 +0000 |
commit | ca488a6d7b6f5701b63249d5a0c73eada09c432c (patch) | |
tree | 85eba69be93a141a99b040a27e74ac61ba54c6c8 /lua | |
parent | 8f80f9fdae13a320da978dffa2c9d94e7b68a810 (diff) | |
download | libguestfs-ca488a6d7b6f5701b63249d5a0c73eada09c432c.tar.gz libguestfs-ca488a6d7b6f5701b63249d5a0c73eada09c432c.tar.xz libguestfs-ca488a6d7b6f5701b63249d5a0c73eada09c432c.zip |
lua: Various fixes to the bindings (thanks Jerome Vuarand).
See http://article.gmane.org/gmane.comp.lang.lua.general/95065
Note that this is incompatible with existing code. You
have to do:
local G = require "guestfs"
local g = G.create ()
ie. give the module your own name ("G" in that example).
Diffstat (limited to 'lua')
-rw-r--r-- | lua/examples/create_disk.lua | 6 | ||||
-rw-r--r-- | lua/examples/guestfs-lua.pod | 20 | ||||
-rw-r--r-- | lua/examples/inspect_vm.lua | 6 | ||||
-rwxr-xr-x | lua/tests/015-globals.lua | 14 | ||||
-rwxr-xr-x | lua/tests/020-create.lua | 4 | ||||
-rwxr-xr-x | lua/tests/025-create-flags.lua | 4 | ||||
-rwxr-xr-x | lua/tests/027-create-multiple.lua | 8 | ||||
-rwxr-xr-x | lua/tests/030-config.lua | 4 | ||||
-rwxr-xr-x | lua/tests/050-lvcreate.lua | 4 | ||||
-rwxr-xr-x | lua/tests/060-readdir.lua | 4 | ||||
-rwxr-xr-x | lua/tests/070-optargs.lua | 4 | ||||
-rwxr-xr-x | lua/tests/400-events.lua | 6 | ||||
-rwxr-xr-x | lua/tests/400-progress.lua | 4 |
13 files changed, 49 insertions, 39 deletions
diff --git a/lua/examples/create_disk.lua b/lua/examples/create_disk.lua index 2dfc1fc2..c662a2c5 100644 --- a/lua/examples/create_disk.lua +++ b/lua/examples/create_disk.lua @@ -1,10 +1,10 @@ -- Example showing how to create a disk image. -require "guestfs" +local G = require "guestfs" -output = "disk.img" +local output = "disk.img" -g = Guestfs.create () +local g = G.create () -- Create a raw-format sparse disk image, 512 MB in size. file = io.open (output, "w") diff --git a/lua/examples/guestfs-lua.pod b/lua/examples/guestfs-lua.pod index 18d427b5..193a9a97 100644 --- a/lua/examples/guestfs-lua.pod +++ b/lua/examples/guestfs-lua.pod @@ -6,8 +6,8 @@ guestfs-lua - How to use libguestfs from Lua =head1 SYNOPSIS - require "guestfs" - g = Guestfs.create () + local G = require "guestfs" + g = G.create () g:add_drive ("test.img", { format = "raw", readonly = true }) g:launch () devices = g:list_devices () @@ -20,15 +20,25 @@ programming language. This page just documents the differences from the C API and gives some examples. If you are not familiar with using libguestfs, you also need to read L<guestfs(3)>. +=head2 REQUIRING THE MODULE + +C<require "guestfs"> returns the module, so you have to assign it +to a local variable. Typical usage is: + + local G = require "guestfs" + +(you can use any name you want instead of C<G>, but in the examples +in this man page we always use C<G>). + =head2 OPENING AND CLOSING THE HANDLE To create a new handle, call: - g = Guestfs.create () + g = G.create () You can also use the optional arguments: - g = Guestfs.create { environment = 0, close_on_exit = 0 } + g = G.create { environment = 0, close_on_exit = 0 } to set the flags C<GUESTFS_CREATE_NO_ENVIRONMENT> and/or C<GUESTFS_CREATE_NO_CLOSE_ON_EXIT>. @@ -95,7 +105,7 @@ second argument a list: eh = g:set_event_callback (cb, { "appliance", "library", "trace" }) A list of all valid event types (strings) is in the global variable -C<Guestfs.event_all>. +C<G.event_all>. The callback (C<cb>) is called with the following parameters: diff --git a/lua/examples/inspect_vm.lua b/lua/examples/inspect_vm.lua index 1bee10b3..e35b4631 100644 --- a/lua/examples/inspect_vm.lua +++ b/lua/examples/inspect_vm.lua @@ -1,6 +1,6 @@ -- Example showing how to inspect a virtual machine disk. -require "guestfs" +local G = require "guestfs" if table.getn (arg) == 1 then disk = arg[1] @@ -8,7 +8,7 @@ else error ("usage: inspect_vm disk.img") end -g = Guestfs.create () +local g = G.create () -- Attach the disk image read-only to libguestfs. g:add_drive (disk, { -- format:"raw" @@ -18,7 +18,7 @@ g:add_drive (disk, { -- format:"raw" g:launch () -- Ask libguestfs to inspect for operating systems. -roots = g:inspect_os () +local roots = g:inspect_os () if table.getn (roots) == 0 then error ("inspect_vm: no operating systems found") end diff --git a/lua/tests/015-globals.lua b/lua/tests/015-globals.lua index ee69f40c..9733ef5c 100755 --- a/lua/tests/015-globals.lua +++ b/lua/tests/015-globals.lua @@ -16,11 +16,11 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -assert (Guestfs._COPYRIGHT) -print ("_COPYRIGHT = ", Guestfs._COPYRIGHT) -assert (Guestfs._DESCRIPTION) -print ("_DESCRIPTION = ", Guestfs._DESCRIPTION) -assert (Guestfs._VERSION) -print ("_VERSION = ", Guestfs._VERSION) +assert (G._COPYRIGHT) +print ("_COPYRIGHT = ", G._COPYRIGHT) +assert (G._DESCRIPTION) +print ("_DESCRIPTION = ", G._DESCRIPTION) +assert (G._VERSION) +print ("_VERSION = ", G._VERSION) diff --git a/lua/tests/020-create.lua b/lua/tests/020-create.lua index 527aa0bc..b7e748d6 100755 --- a/lua/tests/020-create.lua +++ b/lua/tests/020-create.lua @@ -16,6 +16,6 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -local g = Guestfs.create () +local g = G.create () diff --git a/lua/tests/025-create-flags.lua b/lua/tests/025-create-flags.lua index 881b1834..08865c70 100755 --- a/lua/tests/025-create-flags.lua +++ b/lua/tests/025-create-flags.lua @@ -16,6 +16,6 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -local g = Guestfs.create { environment = 0 } +local g = G.create { environment = 0 } diff --git a/lua/tests/027-create-multiple.lua b/lua/tests/027-create-multiple.lua index bd6cae56..a3f8c8cf 100755 --- a/lua/tests/027-create-multiple.lua +++ b/lua/tests/027-create-multiple.lua @@ -16,11 +16,11 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -g1 = Guestfs.create () -g2 = Guestfs.create () -g3 = Guestfs.create () +local g1 = G.create () +local g2 = G.create () +local g3 = G.create () -- Check that each handle is independent. g1:set_path ("1") diff --git a/lua/tests/030-config.lua b/lua/tests/030-config.lua index 53e47fc8..d70528c0 100755 --- a/lua/tests/030-config.lua +++ b/lua/tests/030-config.lua @@ -16,9 +16,9 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -local g = Guestfs.create () +local g = G.create () local verbose = g:get_verbose () g:set_verbose (true) diff --git a/lua/tests/050-lvcreate.lua b/lua/tests/050-lvcreate.lua index 3bd95c23..9fd5bec7 100755 --- a/lua/tests/050-lvcreate.lua +++ b/lua/tests/050-lvcreate.lua @@ -16,9 +16,9 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -local g = Guestfs.create () +local g = G.create () file = io.open ("test.img", "w") file:seek ("set", 500 * 1024 * 1024) diff --git a/lua/tests/060-readdir.lua b/lua/tests/060-readdir.lua index 07e8e3ba..b1481370 100755 --- a/lua/tests/060-readdir.lua +++ b/lua/tests/060-readdir.lua @@ -16,9 +16,9 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -local g = Guestfs.create () +local g = G.create () file = io.open ("test.img", "w") file:seek ("set", 10 * 1024 * 1024) diff --git a/lua/tests/070-optargs.lua b/lua/tests/070-optargs.lua index fe0ec753..00559a1b 100755 --- a/lua/tests/070-optargs.lua +++ b/lua/tests/070-optargs.lua @@ -16,9 +16,9 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -local g = Guestfs.create () +local g = G.create () g:add_drive ("/dev/null") g:add_drive ("/dev/null", { readonly = true }) diff --git a/lua/tests/400-events.lua b/lua/tests/400-events.lua index 47a86a5e..c17bdc27 100755 --- a/lua/tests/400-events.lua +++ b/lua/tests/400-events.lua @@ -16,13 +16,13 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -for i, v in ipairs (Guestfs.event_all) do +for i, v in ipairs (G.event_all) do print (i, v) end -g = Guestfs.create () +local g = G.create () function log_callback (g, event, eh, flags, buf, array) io.write (string.format ("lua event logged: event=%s eh=%d buf='%s'\n", diff --git a/lua/tests/400-progress.lua b/lua/tests/400-progress.lua index e0e17ac8..293a4631 100755 --- a/lua/tests/400-progress.lua +++ b/lua/tests/400-progress.lua @@ -16,9 +16,9 @@ -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -require "guestfs" +local G = require "guestfs" -g = Guestfs.create () +local g = G.create () g:add_drive ("/dev/null") g:launch () |