Read Lua configuration file
authorEnrico Zini <enrico@enricozini.org>
Wed, 6 Jan 2010 11:04:40 +0000 (12:04 +0100)
committerEnrico Zini <enrico@enricozini.org>
Wed, 6 Jan 2010 11:04:40 +0000 (12:04 +0100)
README
src/CMakeLists.txt
src/config.vala

diff --git a/README b/README
index 82acb4a5283c683234f7ca8d035fb409ac1af6e9..824573c7a4eefa726cfa0603c8c0b76b5cc3507e 100644 (file)
--- a/README
+++ b/README
@@ -171,7 +171,6 @@ TODO list / wish list
     - playlist as reorderable standard list, allow to delete tracks, reorder tracks
     - save playlist to file to reload later
     - pause with headset button
- - lua config
  - battery without devkit: do the parsing via lua
  - contacts: show as a fancy focus+context list (see prefuse)
     - vcard on e-vcard.{h,c}
index 5bd4bd89b591826c487d923fbb3ab476d80cfa73..bc5887c971b2e5f2ba66df31aa579bf40dbaa08b 100644 (file)
@@ -3,7 +3,7 @@ include(../vala.cmake)
 
 set(zavai_version 0.1)
 
-set(packages gtk+-2.0 dbus-glib-1>=0.80 libwnck-1.0>=2.26.0 libomhacks)
+set(packages gtk+-2.0 dbus-glib-1>=0.80 libwnck-1.0>=2.26.0 lua5.1 libomhacks)
 add_packages(ZAVAI ${packages})
 
 set(VALA_PACKAGES ${packages} posix linux-input dbus-extra gtkfisheyelist)
index f3de7489114cbb05d43623aeccbaf73b67f2ade4..387546e49d9210dc9263b023a5ec6516da8a3a9d 100644 (file)
@@ -22,33 +22,115 @@ namespace zavai {
 
 public class Config
 {
-    public string version { get; set; }
-    public string homedir { get; set; }
-    public string icondir { get; set; }
-    public int min_button_height { get; set; }
-    public string gprs_apn { get; set; }
-    public string gprs_user { get; set; }
-    public string gprs_pass { get; set; }
-    public int backlight_max { get; set; }
+    protected Lua.LuaVM lua;
+    protected weak string get_string(string name)
+    {
+        lua.get_global(name);
+        weak string res = lua.to_string(-1);
+        lua.pop(1);
+        return res;
+    }
+    protected void set_string(string name, string? val)
+    {
+        if (val == null)
+            lua.push_nil();
+        else
+            lua.push_string(val);
+        lua.set_global(name);
+    }
+    protected weak int get_int(string name)
+    {
+        lua.get_global(name);
+        int res = lua.to_integer(-1);
+        lua.pop(1);
+        return res;
+    }
+    protected void set_int(string name, int val)
+    {
+        lua.push_integer(val);
+        lua.set_global(name);
+    }
+
+    public string version
+    {
+        get { return get_string("version"); }
+        set { set_string("version", value); }
+    }
+    public string homedir
+    {
+        get { return get_string("homedir"); }
+        set { set_string("homedir", value); }
+    }
+    public string icondir
+    {
+        get { return get_string("icondir"); }
+        set { set_string("icondir", value); }
+    }
+    public int min_button_height
+    {
+        get { return get_int("min_button_height"); }
+        set { set_int("min_button_height", value); }
+    }
+    public string gprs_apn
+    {
+        get { return get_string("gprs_apn"); }
+        set { set_string("gprs_apn", value); }
+    }
+    public string gprs_user
+    {
+        get { return get_string("gprs_user"); }
+        set { set_string("gprs_user", value); }
+    }
+    public string gprs_pass
+    {
+        get { return get_string("gprs_pass"); }
+        set { set_string("gprs_pass", value); }
+    }
+    public int backlight_max
+    {
+        get;
+        set;
+    }
     private string _argv0;
     public string argv0 {
-           get { return _argv0; }
-           set { _argv0 = value; }
+        get { return _argv0; }
+        set { _argv0 = value; }
     }
 
     public Config()
     {
+        lua = new Lua.LuaVM();
+        lua.open_libs();
+
+stderr.printf("ZA1\n");
+
         // Set defaults
         version = "0.1";
+stderr.printf("ZA2\n");
         homedir = GLib.Environment.get_home_dir() + "/.zavai";
+stderr.printf("ZA3\n");
         icondir = GLib.Environment.get_variable("ZAVAI_ICONDIR");
+stderr.printf("ZA4\n");
         if (icondir == null)
                 icondir = "/usr/share/zavai/icons";
+stderr.printf("ZA5\n");
         min_button_height = 80;
+stderr.printf("ZA6\n");
         gprs_apn = "general.t-mobile.uk";
+stderr.printf("ZA7\n");
         gprs_user = "x";
+stderr.printf("ZA8\n");
         gprs_pass = "x";
-       backlight_max = 15;
+stderr.printf("ZA9\n");
+        backlight_max = 15;
+stderr.printf("ZA10\n");
+
+        // Read config
+        if (lua.do_file(homedir + "/config"))
+        {
+            zavai.log.error("Failed to parse " + homedir + "/config: " + lua.to_string(-1));
+        }
+stderr.printf("ZA11\n");
     }
 
 /*