Created
June 1, 2013 13:30
-
-
Save khajavi/5690383 to your computer and use it in GitHub Desktop.
Example of creating new GObject class in Vala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* main.c generated by valac 0.12.1, the Vala compiler | |
* generated from main.vala, do not modify */ | |
#include <glib.h> | |
#include <glib-object.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define TYPE_PROTOTYPE (prototype_get_type ()) | |
#define PROTOTYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROTOTYPE, Prototype)) | |
#define PROTOTYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROTOTYPE, PrototypeClass)) | |
#define IS_PROTOTYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROTOTYPE)) | |
#define IS_PROTOTYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROTOTYPE)) | |
#define PROTOTYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROTOTYPE, PrototypeClass)) | |
typedef struct _Prototype Prototype; | |
typedef struct _PrototypeClass PrototypeClass; | |
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) | |
void _vala_main (gchar** args, int args_length1); | |
Prototype* prototype_new (void); | |
Prototype* prototype_construct (GType object_type); | |
GType prototype_get_type (void) G_GNUC_CONST; | |
void _vala_main (gchar** args, int args_length1) { | |
Prototype* _tmp0_ = NULL; | |
Prototype* prototype; | |
_tmp0_ = prototype_new (); | |
prototype = _tmp0_; | |
_g_object_unref0 (prototype); | |
} | |
int main (int argc, char ** argv) { | |
g_type_init (); | |
_vala_main (argv, argc); | |
return 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main( string[] args ) { | |
var prototype = new Prototype(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#prototype: Prototype.vala main.vala | |
# valac -C Prototype.vala main.vala | |
main: main.c Prototype.c | |
gcc main.c Prototype.c -o main.bin `pkg-config glib-2.0 gtk+-2.0 --cflags --libs` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Prototype.c generated by valac 0.12.1, the Vala compiler | |
* generated from Prototype.vala, do not modify */ | |
#include <glib.h> | |
#include <glib-object.h> | |
#define TYPE_PROTOTYPE (prototype_get_type ()) | |
#define PROTOTYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROTOTYPE, Prototype)) | |
#define PROTOTYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROTOTYPE, PrototypeClass)) | |
#define IS_PROTOTYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROTOTYPE)) | |
#define IS_PROTOTYPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROTOTYPE)) | |
#define PROTOTYPE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROTOTYPE, PrototypeClass)) | |
typedef struct _Prototype Prototype; | |
typedef struct _PrototypeClass PrototypeClass; | |
typedef struct _PrototypePrivate PrototypePrivate; | |
struct _Prototype { | |
GObject parent_instance; | |
PrototypePrivate * priv; | |
}; | |
struct _PrototypeClass { | |
GObjectClass parent_class; | |
}; | |
static gpointer prototype_parent_class = NULL; | |
GType prototype_get_type (void) G_GNUC_CONST; | |
enum { | |
PROTOTYPE_DUMMY_PROPERTY | |
}; | |
Prototype* prototype_new (void); | |
Prototype* prototype_construct (GType object_type); | |
static void prototype_finalize (GObject* obj); | |
Prototype* prototype_construct (GType object_type) { | |
g_printf("\"%s\" function is called\n", __FUNCTION__); | |
Prototype * self = NULL; | |
self = (Prototype*) g_object_new (object_type, NULL); | |
return self; | |
} | |
Prototype* prototype_new (void) { | |
g_printf("\"%s\" function is called\n", __FUNCTION__); | |
return prototype_construct (TYPE_PROTOTYPE); | |
} | |
static void prototype_class_init (PrototypeClass * klass) { | |
g_printf("\"%s\" function is called\n", __FUNCTION__); | |
prototype_parent_class = g_type_class_peek_parent (klass); | |
G_OBJECT_CLASS (klass)->finalize = prototype_finalize; | |
} | |
static void prototype_instance_init (Prototype * self) { | |
g_printf("\"%s\" function is called\n", __FUNCTION__); | |
} | |
static void prototype_finalize (GObject* obj) { | |
g_printf("\"%s\" function is called\n", __FUNCTION__); | |
Prototype * self; | |
self = PROTOTYPE (obj); | |
G_OBJECT_CLASS (prototype_parent_class)->finalize (obj); | |
} | |
GType prototype_get_type (void) { | |
g_printf("\"%s\" function is called\n", __FUNCTION__); | |
static volatile gsize prototype_type_id__volatile = 0; | |
if (g_once_init_enter (&prototype_type_id__volatile)) { | |
static const GTypeInfo g_define_type_info = { sizeof (PrototypeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) prototype_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Prototype), 0, (GInstanceInitFunc) prototype_instance_init, NULL }; | |
GType prototype_type_id; | |
prototype_type_id = g_type_register_static (G_TYPE_OBJECT, "Prototype", &g_define_type_info, 0); | |
g_once_init_leave (&prototype_type_id__volatile, prototype_type_id); | |
} | |
return prototype_type_id__volatile; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Prototype : Object { | |
~Prototype() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment