X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/0f7ec1e61526025bc5441210f6f2f9e6995c8bac..185449d25b2f9c93d2928e4745e8aa64d7d9ab9c:/t/str.gob diff --git a/t/str.gob b/t/str.gob new file mode 100644 index 0000000..4936879 --- /dev/null +++ b/t/str.gob @@ -0,0 +1,73 @@ +// A simple string class, a lot like GString but with full GObject +// machinery and really short method names for the lazy :) + +%{ +#include +%} + +class :Str from G:Object { + + private GString *contents; + + public + void + print (self) + { + g_print ("%s", self->_priv->contents->str); + } + + public + GObject * + new (const char *format (check null), ...) attr {G_GNUC_PRINTF (1, 2)} + onerror NULL defreturn NULL + { + va_list ap; + va_start (ap, format); + gchar *tmp = g_strdup_vprintf (format, ap); + va_end (ap); + + Self *self = (Self *) GET_NEW; + + self->_priv->contents = g_string_new (tmp); + + g_free (tmp); + + return G_OBJECT (self); + } + + // It seems gob accepts defreturn on non-virtual non-signal types + // without complaint, though from the man page I'm not sure the + // resulting behavior is well defined. + public + char * + nonvirt_test (self, const char *format (check null), ...) + attr {G_GNUC_PRINTF (2,3)} + defreturn NULL + { + return NULL; + } + + private + char * + private_test_method (self, const char *format (check null), ...) + attr {G_GNUC_PRINTF (2, 3)} + defreturn NULL + { + return NULL; + } + + public + char * + private_method_caller (self) + { + int much_too_general = 42; + + // This should trigger a warning. + self_private_test_method (self, "want a string: %s", much_too_general); + + // So should this. + str_private_test_method (self, "want a string: %s", much_too_general); + + return NULL; + } +}