Lua:将使用xmldbus定义发出消息的Python代码翻译成Lua

Lua:将使用xmldbus定义发出消息的Python代码翻译成Lua,lua,dbus,lgi,Lua,Dbus,Lgi,我是在评论之前的一个问题时问这个问题的,但我认为最好把它作为一个新的独立问题转移到这里 我试图找出如何使用lgi dbus将此Python代码转换为Lua,以发出dbus信号: class DBUSTestInterface(object): """ Server_XML definition. Emit / Publish a signal that is a random integer every second type='i' for integer.

我是在评论之前的一个问题时问这个问题的,但我认为最好把它作为一个新的独立问题转移到这里

我试图找出如何使用lgi dbus将此Python代码转换为Lua,以发出dbus信号:

class DBUSTestInterface(object):
    """
    Server_XML definition.
    Emit / Publish a signal that is a random integer every second 
    type='i' for integer. 
    """
    dbus = """
    <node>
        <interface name="com.test.device.aaa">
            <signal name="get">
                <arg type='s'/>
                <arg type='s'/>
                <arg type='s'/>
                <arg type='s'/>
                <arg type='s'/>
                <arg type='s'/>
                <arg type='s'/>
                <arg type='i'/>
            </signal>
        </interface>
    </node>
    """
    get = signal()

emit = DBUSTestInterface()
bus.publish("com.test.device.get", emit)
但我不确定,我也不知道如何使用Python中的XML设置消息体

如果你能提供一些例子或指出我在哪里可以找到它,我将不胜感激


谢谢

嘿,谷歌带我来这里看看

不知何故,我觉得您的代码示例不能像一些自包含的python代码那样工作。因此,我将采用文本中的评论:

每秒发射/发布一个随机整数信号

LUA代码,除了“随机整数”之外,除非您考虑<代码> 42 /代码>是随机的:

local object = "/org/freedesktop/DBus"
local interface = "org.freedesktop.DBus.Introspectable"
local method = "Introspect"
local message = Gio.DBusMessage.new_method_call(name, object, interface, method)
message:set_body(GLib.Variant("(aoo)", {{location},session})) -- How do I set the same message as above?
local lgi = require("lgi")
local Gio, GLib, GObject = lgi.Gio, lgi.GLib, lgi.GObject

local conn

GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, function()
    if conn then
        conn:emit_signal(nil, "/your/example/has/no/path",
            "com.test.device.aaa", "get",
            GLib.Variant("(sssssssi)", { "what", "are", "all",
            "these", "strings", "for", "?", 42 }))
    end
    return true
end)

local function on_bus_acquire(con)
    conn = con

    local function arg(name, signature)
        return Gio.DBusArgInfo{ name = name, signature = signature }
    end
    local interface_info = Gio.DBusInterfaceInfo {
        name = "com.test.device.aaa",
        signals = {
            Gio.DBusSignalInfo{
                name = "get",
                args = {
                    arg("no_name?!?", "s"),
                    arg("no_name?!?", "s"),
                    arg("no_name?!?", "s"),
                    arg("no_name?!?", "s"),
                    arg("no_name?!?", "s"),
                    arg("no_name?!?", "s"),
                    arg("no_name?!?", "s"),
                    arg("no_name?!?", "i")
                }
            }
        }
    }
    conn:register_object("/your/example/has/no/path", interface_info, nil)
end

Gio.bus_own_name(Gio.BusType.SESSION, "com.test.device.get", Gio.BusNameOwnerFlags.NONE,
    GObject.Closure(on_bus_acquire), nil, nil)

GLib.MainLoop.new():run()