[Vala] [PATCH]Add an option to valac for passing args to pkg-config

2012-09-15 Thread Kder
I added a feature(command line option) for the vala compiler:

 -p, --pkg-config-args=ARGS Pass ARGS to pkg-config utility

to pass customized arguments to pkg-config utility.

For example, we can use this to static compile a gtk program with valac:

valac test_static.vala -p --static --libs gtk+-2.0 gee-0.8 --pkg gee-0.8 --
pkg gtk+-2.0 -X -static

Here is the patch:

diff -Nuar vala-0.17.5/codegen/valaccodecompiler.vala vala-0.17.5-patched/
codegen/valaccodecompiler.vala
--- vala-0.17.5/codegen/valaccodecompiler.vala  2012-08-06 19:19:28 +0800
+++ vala-0.17.5-patched/codegen/valaccodecompiler.vala  2012-08-24 12:56:05 
+0800
@@ -51,9 +51,13 @@
public void compile (CodeContext context, string? cc_command, string[] 
cc_options) {
bool use_pkgconfig = false;
 
-   string pc = pkg-config --cflags;
+   string pc = pkg-config --cflags ;
if (!context.compile_only) {
-   pc +=  --libs;
+  if (context.pkg_config_args != null) {
+  pc += context.pkg_config_args;
+  } else {
+  pc +=  --libs;
+  }
}
use_pkgconfig = true;
pc +=  gobject-2.0;
diff -Nuar vala-0.17.5/compiler/valacompiler.vala vala-0.17.5-patched/compiler/
valacompiler.vala
--- vala-0.17.5/compiler/valacompiler.vala  2012-08-06 19:57:53 +0800
+++ vala-0.17.5-patched/compiler/valacompiler.vala  2012-08-24 12:44:35 
+0800
@@ -79,6 +79,8 @@
static bool disable_version_header;
static bool fatal_warnings;
static string dependencies;
+   
+   static string pkg_config_args;
 
static string entry_point;
 
@@ -108,6 +110,7 @@
{ deps, 0, 0, OptionArg.STRING, ref dependencies, Write make-
style dependency information to this file, null },
{ symbols, 0, 0, OptionArg.FILENAME, ref symbols_filename, 
Output symbols file, FILE },
{ compile, 'c', 0, OptionArg.NONE, ref compile_only, Compile 
but do not link, null },
+   { pkg-config-args, 'p', 0, OptionArg.STRING, ref 
pkg_config_args, Pass ARGS to pkg-config utility, ARGS },
{ output, 'o', 0, OptionArg.FILENAME, ref output, Place 
output in file FILE, FILE },
{ debug, 'g', 0, OptionArg.NONE, ref debug, Produce debug 
information, null },
{ thread, 0, 0, OptionArg.NONE, ref thread, Enable 
multithreading support, null },
@@ -181,6 +184,7 @@
 
context.ccode_only = ccode_only;
context.compile_only = compile_only;
+   context.pkg_config_args = pkg_config_args;
context.header_filename = header_filename;
if (header_filename == null  use_header) {
Report.error (null, --use-header may only be used in 
combination with --header);
diff -Nuar vala-0.17.5/vala/valacodecontext.vala vala-0.17.5-patched/vala/
valacodecontext.vala
--- vala-0.17.5/vala/valacodecontext.vala   2012-08-07 02:15:43 +0800
+++ vala-0.17.5-patched/vala/valacodecontext.vala   2012-08-24 12:52:41 
+0800
@@ -89,6 +89,11 @@
public bool compile_only { get; set; }
 
/**
+   * Pass args to pkg-config.
+   */
+   public string pkg_config_args { get; set; }
+
+   /**
 * Output filename.
 */
public string output { get; set; }



___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] [PATCH]Add an option to valac for passing args to pkg-config

2012-09-15 Thread Kder
Sorry for the word wrapping problem in my last message. This is my patch:


diff -Nuar vala-0.17.5/codegen/valaccodecompiler.vala vala-0.17.5-patched/
codegen/valaccodecompiler.vala
--- vala-0.17.5/codegen/valaccodecompiler.vala  2012-08-06 19:19:28 +0800
+++ vala-0.17.5-patched/codegen/valaccodecompiler.vala  2012-08-24 12:56:05 
+0800
@@ -51,9 +51,13 @@
public void compile (CodeContext context, string? cc_command, string[] 
cc_options) {
bool use_pkgconfig = false;
 
-   string pc = pkg-config --cflags;
+   string pc = pkg-config --cflags ;
if (!context.compile_only) {
-   pc +=  --libs;
+  if (context.pkg_config_args != null) {
+  pc += context.pkg_config_args;
+  } else {
+  pc +=  --libs;
+  }
}
use_pkgconfig = true;
pc +=  gobject-2.0;
diff -Nuar vala-0.17.5/compiler/valacompiler.vala vala-0.17.5-patched/compiler/
valacompiler.vala
--- vala-0.17.5/compiler/valacompiler.vala  2012-08-06 19:57:53 +0800
+++ vala-0.17.5-patched/compiler/valacompiler.vala  2012-08-24 12:44:35 
+0800
@@ -79,6 +79,8 @@
static bool disable_version_header;
static bool fatal_warnings;
static string dependencies;
+   
+   static string pkg_config_args;
 
static string entry_point;
 
@@ -108,6 +110,7 @@
{ deps, 0, 0, OptionArg.STRING, ref dependencies, Write make-
style dependency information to this file, null },
{ symbols, 0, 0, OptionArg.FILENAME, ref symbols_filename, 
Output symbols file, FILE },
{ compile, 'c', 0, OptionArg.NONE, ref compile_only, Compile 
but do not link, null },
+   { pkg-config-args, 'p', 0, OptionArg.STRING, ref 
pkg_config_args, Pass ARGS to pkg-config utility, ARGS },
{ output, 'o', 0, OptionArg.FILENAME, ref output, Place 
output in file FILE, FILE },
{ debug, 'g', 0, OptionArg.NONE, ref debug, Produce debug 
information, null },
{ thread, 0, 0, OptionArg.NONE, ref thread, Enable 
multithreading support, null },
@@ -181,6 +184,7 @@
 
context.ccode_only = ccode_only;
context.compile_only = compile_only;
+   context.pkg_config_args = pkg_config_args;
context.header_filename = header_filename;
if (header_filename == null  use_header) {
Report.error (null, --use-header may only be used in 
combination with --header);
diff -Nuar vala-0.17.5/vala/valacodecontext.vala vala-0.17.5-patched/vala/
valacodecontext.vala
--- vala-0.17.5/vala/valacodecontext.vala   2012-08-07 02:15:43 +0800
+++ vala-0.17.5-patched/vala/valacodecontext.vala   2012-08-24 12:52:41 
+0800
@@ -89,6 +89,11 @@
public bool compile_only { get; set; }
 
/**
+   * Pass args to pkg-config.
+   */
+   public string pkg_config_args { get; set; }
+
+   /**
 * Output filename.
 */
public string output { get; set; }


___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Exposing the CLUTTER_COLOR_* macros in Vala

2012-09-15 Thread Emmanuele Bassi
hi;

On 15 September 2012 02:30, Kerrick Staley m...@kerrickstaley.com wrote:
 I've created a patch for Vala [1] that will expose the CLUTTER_COLOR_*
 macros in Vala as Clutter.Color.*. It maps e.g. CLUTTER_COLOR_Red to
 Clutter.Color.RED and CLUTTER_COLOR_DarkOrange to
 Clutter.Color.DARK_ORANGE. This convention disagrees with
 ClutterStaticColor (but does agree with CLUTTER_COLOR_*). ebassi, do
 you think this convention is OK?

it's a bit icky. the CLUTTER_COLOR_* pre-processor macros were added
mostly for convenience of the C developers, and the fact that they
reference a function makes them invisible for consumers of the
introspection data (the introspection scanner only recognises macros
that evaluates to numbers and strings).

from a Vala perspective, Clutter.Color.* matches the keysym namespace
of Clutter.Key.*, which was the intent on the C side, so it'd be
correct. as for the implementation of the patch, I'll leave it to Vala
developers to actually comment on.

ciao,
 Emmanuele.

-- 
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi/
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] SDL TTF Bindings can't find font

2012-09-15 Thread David Gomes
Hello there, first of all here's the relevant part of my code:

using SDLTTF;

(...)

public void draw_string (string text, int x, int y, Color color) {
Rect destination = {};
Font pixel_font = new Font (font.ttf, 20);
if (pixel_font == null) print (Font not found\n);

(...)
}

Basically, pixel_font is always null and I am sure font.ttf is on the
same directory as the binary executable:

~/src/thegame $ ls
thegame Game.vala Cube.Vala font.ttf Makefile PlayState.vala State.vala
~/src/thegame $ ls

I also tried renaming the file, or putting the font in a special
folder. Oh, and I'm calling the executable on the same directory as
the font and the binary.

Here's my compile line on my Makefile:

valac --pkg gl --pkg sdl --pkg sdl-gfx --pkg gio-2.0 --pkg sdl-image
--pkg sdl-ttf -X -lSDL_gfx -X lSDL_image -X lSDL_ttf
--Xcc=-I/usr/include/SDL -o thegame Game.vala State.vala State.vala
PlayState.vala

It compiles with 0 warnings and 0 errors too by the way.

-- 
David Gomes
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] GObject.get() + struct in Vala is problematic

2012-09-15 Thread Derek Dai
GLib.Object.get() actually is g_object_get() in C.

ClutterColor is registered as a boxed type in GObject's term.

Returns boxed type from g_object_get() in GObject type system will make a
copy with g_boxed_copy() first, so, what you get is a pointer instead of
simple value (pass by value).

Here is the sample code in C
ClutterColor * bg;
ClutterActor * actor = clutter_rectangle();
g_object_get(actor, background-color,  bg, NULL);
g_message(%d, %d, %d, %d, bg-red, bg-green, bg-blue, bg-alpha);
clutter_color_free(bg);
g_object_unref(actor);

$ gcc -o test test.c $(pkg-config --libs --cflags clutter-1.0)  ./test
** Message: 0, 0, 0, 0

Because GObject type system return a address of a copied ClutterColor, the
third parameter must be a pointer to ClutterColor pointer (ColorColor **)
instead of ClutterColor pointer (ClutterColor *).

The above sample code in Vala
Clutter.Color bg;
Clutter.Actor actor = new Clutter.Rectangle();
actor.get(background-color, out bg);
message(%d, %d, %d, %d, bg.red, bg.green, bg.blue, bg.alpha);

$ valac -o test test.vala --pkg=clutter-1.0  ./test
** Message: test.vala:8: 40, 129, 22, 8

Generated C code looks like
ClutterColor bg;
ClutterActor * actor = clutter_rectangle();
g_object_get(actor, background-color,  bg, NULL);
g_object_unref(actor);

The value filled into bg is not the color value but address of copied
ClutterColor.

If we declare bg as a ClutterColor pointer
Clutter.Color * bg;
Clutter.Actor actor = new Clutter.Rectangle();
actor.get(background-color, out bg);
message(%d, %d, %d, %d, bg-red, bg-green, bg-blue, bg-alpha);

$ valac -o test test.vala --pkg=clutter-1.0  ./test
** Message: test.vala:8: 0, 0, 0, 0

It is the expected result (but I don't know how to free the returned bg).

Derek Dai


On Sat, Sep 15, 2012 at 3:53 PM, vala-list-requ...@gnome.org wrote:

 Re: [Vala] GObject.get() + struct in Vala is problematic
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] SDL TTF Bindings can't find font

2012-09-15 Thread tarnyko


Hi David, 

Do you have the following line at the beginning of your method : 

SDLTTF.init (); 



Regards, Tarnyko 




David Gomes writes: 

Hello there, first of all here's the relevant part of my code: 

using SDLTTF; 

(...) 


public void draw_string (string text, int x, int y, Color color) {
Rect destination = {};
Font pixel_font = new Font (font.ttf, 20);
if (pixel_font == null) print (Font not found\n); 


(...)
} 


Basically, pixel_font is always null and I am sure font.ttf is on the
same directory as the binary executable: 


~/src/thegame $ ls
thegame Game.vala Cube.Vala font.ttf Makefile PlayState.vala State.vala
~/src/thegame $ ls 


I also tried renaming the file, or putting the font in a special
folder. Oh, and I'm calling the executable on the same directory as
the font and the binary. 

Here's my compile line on my Makefile: 


valac --pkg gl --pkg sdl --pkg sdl-gfx --pkg gio-2.0 --pkg sdl-image
--pkg sdl-ttf -X -lSDL_gfx -X lSDL_image -X lSDL_ttf
--Xcc=-I/usr/include/SDL -o thegame Game.vala State.vala State.vala
PlayState.vala 

It compiles with 0 warnings and 0 errors too by the way. 


--
David Gomes
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] SDL TTF Bindings can't find font

2012-09-15 Thread David Gomes
Oh, I forgot, thank you tons, that was it!

On 9/15/12, tarn...@tarnyko.net tarn...@tarnyko.net wrote:

 Hi David,

 Do you have the following line at the beginning of your method :

 SDLTTF.init ();


 Regards, Tarnyko



 David Gomes writes:

 Hello there, first of all here's the relevant part of my code:

 using SDLTTF;

 (...)

 public void draw_string (string text, int x, int y, Color color) {
 Rect destination = {};
 Font pixel_font = new Font (font.ttf, 20);
 if (pixel_font == null) print (Font not found\n);

 (...)
 }

 Basically, pixel_font is always null and I am sure font.ttf is on the
 same directory as the binary executable:

 ~/src/thegame $ ls
 thegame Game.vala Cube.Vala font.ttf Makefile PlayState.vala State.vala
 ~/src/thegame $ ls

 I also tried renaming the file, or putting the font in a special
 folder. Oh, and I'm calling the executable on the same directory as
 the font and the binary.

 Here's my compile line on my Makefile:

 valac --pkg gl --pkg sdl --pkg sdl-gfx --pkg gio-2.0 --pkg sdl-image
 --pkg sdl-ttf -X -lSDL_gfx -X lSDL_image -X lSDL_ttf
 --Xcc=-I/usr/include/SDL -o thegame Game.vala State.vala State.vala
 PlayState.vala

 It compiles with 0 warnings and 0 errors too by the way.

 --
 David Gomes
 ___
 vala-list mailing list
 vala-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/vala-list
 ___
 vala-list mailing list
 vala-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/vala-list

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list