Skip to content
forked from stetre/moonusb

Lua bindings for libusb with CMake Support

License

Notifications You must be signed in to change notification settings

OneLuaPro/moonusb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MoonUSB: Lua bindings for libusb

This fork of MoonUSB is prepared for seamless integration into OneLuaPro using CMake build infrastructure. It contains a number of fixes and tweaks to make MoonUSB compatible with MSVC compilers.

The remainder of the README is identical to the original authors's version.


MoonUSB is a Lua binding library for libusb, allowing applications to access and use USB devices. MoonUSB also provides a submodule for emulating USB devices via USB/IP. It runs on GNU/Linux and requires Lua (>=5.3) and libusb (>= 1.0.24).

Author: Stefano Trettel

Lua logo

License

MIT/X11 license (same as Lua). See LICENSE.

Documentation

See the Reference Manual.

Getting and installing

Setup the build environment as described here, then:

$ git clone https://github.com/stetre/moonusb/
$ cd moonusb
moonusb$ make
moonusb$ sudo make install

Example

The example below lists the devices currently attached to the system.

Other examples can be found in the examples/ directory.

-- MoonUSB example: hello.lua
local usb = require("moonusb")

local ctx = usb.init()

local devices = ctx:get_device_list()

for i, dev in ipairs(devices) do
   local descr = dev:get_device_descriptor()
   local devhandle = dev:open()
   print(string.format("USB %s - bus:%d port:%d %.4x:%.4x %s %s (%s)",
      descr.usb_version, dev:get_bus_number(), dev:get_port_number(),
      descr.vendor_id, descr.product_id,
      devhandle:get_string_descriptor(descr.manufacturer_index) or "???",
      devhandle:get_string_descriptor(descr.product_index) or "???",
      descr.class))
   devhandle:close()
   dev:free()
end

The script can be executed at the shell prompt with the standard Lua interpreter:

$ lua hello.lua

See also

About

Lua bindings for libusb with CMake Support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 90.1%
  • Lua 5.8%
  • CMake 3.0%
  • Other 1.1%