GithubHelp home page GithubHelp logo

xuhuashan / simpledbus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kstep/simpledbus

0.0 2.0 0.0 85 KB

Simple DBus bindings for Lua

License: GNU Lesser General Public License v3.0

Makefile 2.20% C 81.41% Lua 16.39%

simpledbus's Introduction

SimpleDBus

About

SimpleDBus is a Lua library which enables you to write simple scripts to act on signals, send signals, call methods on remote objects and export your own objects to DBus.

SimpleDBus implements a simple poll()-based main loop so scripts can act asynchronously over several busses at the same time.

Installation

Get the sources and do

make
make PREFIX=/usr install

This will install the files core.so in /usr/lib/lua/5.1/simpledbus and simpledbus.lua in /usr/share/lua/5.1. Have a look at the makefiles if this isn't right for your system.

Instead of make you can use make allinone to compile all the code in one go. This produces a slightly smaller library.

Alternatively you can use luarocks and just type luarocks make in the source directory.

Make sure you have installed the dbus and expat libraries and their development packages on systems where they are separate. The build process also requires pkgconfig to set up paths for the dbus headers.

Usage

Here is a sample script:

-- import the module
SimpleDBus = require 'simpledbus'

-- initialise and get a handle for the session bus
bus = assert(SimpleDBus.SessionBus())

-- connect to the client connected at org.freedesktop.DBus
-- and get a proxy for the object /org/freedesktop/DBus
DBus = assert(bus:auto_proxy('org.freedesktop.DBus', '/org/freedesktop/DBus'))

-- call a method and print the results nicely
print 'Connections to the session bus:'
for i, s in ipairs(assert(DBus:ListNames())) do
   print(('%4i: %s'):format(i, s))
end

-- register interest in the signal from the
-- object /org/lua/SimpleDBus/Test implementing
-- the interface org.lua.SimpleDBus.TestSignal
-- called Signal
bus:register_signal(
   '/org/lua/SimpleDBus/Test',
   'org.lua.SimpleDBus.TestSignal',
   'Signal',
   function(arg1)
      print('Signal: ' .. tostring(arg1))

      if arg1 == 'stop' then
         SimpleDBus.stop()
      end
   end)

-- now run the main loop and wait for signals to arrive
assert(SimpleDBus.mainloop(bus))

Use the command dbus-send --session --type=signal /org/lua/SimpleDBus/Test org.lua.SimpleDBus.TestSignal.Signal string:stop or run stop.lua in the examples directory to stop this script in a nice way.

For more examples look in the examples directory in the source tree.

License

SimpleDBus is free software. It is distributed under the terms of the GNU General Public License

Contact

Please send bug reports, patches, feature requests, praise and general gossip to me, Emil Renner Berthing [email protected].

simpledbus's People

Contributors

esmil avatar xuhuashan avatar

Watchers

Norman Ramsey avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.