GSubprocess examples in Lua.
Quick start:
local lgi = require("lgi")
local Gio = lgi.require("Gio", "2.0")
--[[
Arguments:
1. The first element is the command to run, the rest are arguments for that command| local lgi = require("lgi") | |
| local Gtk = lgi.Gtk | |
| local GObject = lgi.GObject | |
| local Example = lgi.package("Example") | |
| Example:class("App", Gtk.Application) | |
| Example:class("Header", Gtk.HeaderBar) | |
| Example:class("Window", Gtk.ApplicationWindow) | |
| function Example.App:_init( ... ) |
| local lgi = require("lgi") | |
| local GObject = lgi.require("GObject", "2.0") | |
| -- Our new class inherits directly from GObject | |
| local Person = GObject.Object:derive("Person") | |
| -- Class constructor, used by GObject. This function | |
| -- is called one time and is for register our class. | |
| -- Inside this function we can do some things like | |
| -- create some properties, signals and override some |
| local lgi = require("lgi") | |
| local Gio = lgi.require("Gio", "2.0") | |
| local Content = {} | |
| local Dir = "" | |
| function ReadDir(Path, Tab, Indent) | |
| local file = Gio.File.new_for_path(Path) | |
| local enum = file:enumerate_children("standard::name", Gio.FileQueryInfoFlags.NONE) | |
| local path = file:get_path() .. "/" |
| -- From my other Gist: https://gist.github.com/M1que4s/9f1eec873f87cb02238bd6de2d435705 | |
| local lgi = require("lgi") | |
| local GObject = lgi.require("GObject", "2.0") | |
| local Canonical = GObject.Object:derive("Canonical") | |
| function Canonical:_class_init(Class) | |
| function Class:set_property(id, val, pspec) | |
| if id == 1 then self.priv["prop-a"] = val:get_string() | |
| elseif id == 2 then self.priv["prop-b"] = val:get_string() |
| local lgi = require("lgi") | |
| local GLib = lgi.require("GLib", "2.0") | |
| --[[ Explanation | |
| Some multimedia apps (music players, for example) that uses GLib and related libraries (Gtk, | |
| GObject, GStreamer, etc...) commonly auto-detects user directories that contains specific | |
| things like music, videos, pictures and documents. That's nice, but... How is it done? | |
| Well... Here's the answer: |
GSubprocess examples in Lua.
Quick start:
local lgi = require("lgi")
local Gio = lgi.require("Gio", "2.0")
--[[
Arguments:
1. The first element is the command to run, the rest are arguments for that command| package main | |
| // We need only this modules | |
| import ( | |
| "os" // For open the file | |
| "fmt" // For print data | |
| "io/ioutil" // For read data | |
| ) | |
| // A little function for error checking |
| package main | |
| import ( | |
| // For the exit status | |
| OS "os" | |
| // For printing | |
| Fmt "fmt" | |
| // For commandline arguments | |
| Flag "flag" | |
| // For requests |
| package main | |
| import ( | |
| // For printing | |
| Fmt "fmt" | |
| // For arguments parsing | |
| Flag "flag" | |
| ) | |
| // Defines a flag for the commandline. Refers to the doc for details: |
| package main | |
| import ( | |
| Fmt "fmt" | |
| Str "strings" | |
| Bytes "bytes" | |
| JSON "encoding/json" | |
| ) | |
| // Our JSON string to decode |