Vala and Genie programming

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#61 Post by MU »

Code: Select all

[indent=2]


def getTime() : string
              
  return GLib.Time.local(time_t ()).to_string()

init 
      
   //-- display the current time --    

   print ("%s" , getTime()) 
   
   
   
   //-- run a timer to check how long a code needs --
   timer : Timer = new Timer()
   timer.start()
   
   for var n = 0 to 10000
     print ("%d" , n)
     
   timer.stop()

   print ("%f seconds were needed." , timer.elapsed() )
   
   
   
http://valadoc.org/?pkg=glib-2.0&element=GLib.Timer

Vala should support multithreaded programming, but you must explicitly create such threads.
The above example does not use threads, just a "for" loop, to print some values.
The timer checks, how long it takes to print them.

And now eat some fish *mjam :)
Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#62 Post by Lobster »

And now eat some fish *mjam
never heard of that . . .
does it come with chips (fries)?

Thanks Mark
this is what I got

Code: Select all

# valac timer.gs
# ./timer

Segmentation fault
probably need the rest of the week to figure it out now . ..
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#63 Post by MU »

try:
gdb ./timer

This starts the debugger. There type:

run

When it crashes, type:
backtrace

This should show some strange looking functions.
Please copy & paste them here.

Then type to exit the debugger:
quit

----------
The fish I eat with cooked potatoes and butter :)
Was gooood, although it was from the supermarket.

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#64 Post by Lobster »

Code: Select all

(gdb) run
Starting program: /root/zz_imt3/timer 
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)


Program received signal SIGSEGV, Segmentation fault.
0xb7e6c6f2 in strcmp () from /lib/libc.so.6
(gdb) quit
this debugger is part of gcc?

ah fish
for supper I had frozen hake (an Alaskan fish) with coconut milk and Jamaican chilli
with potatoes and olive oil and Christmas pudding - better late then never . . .yum - good supper - oh and a salad . . . oh and red nose day wine (it is a comedy wine)
m m m . . . this might explain why my wii sport exercise routine is making me feel much fitter but no weight loss . . .
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#65 Post by MU »

hm, I have no strcmp () in my C code.
Please run:
valac -C timer.gs

Then paste here timer.c.

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#66 Post by MU »

for me the example works in Puppy 4.12.
I attach the project.
Extract it in the project folder, and open it in the Valaide.

Or compile main.gs by hand:
valac main.gs
./main


Maybe you added something, or there was an error caused by copy&paste from your webbrowser.
I had encountered this in the past, maybe webbrowsers add different linefeeds or whatever.

I use
gtksourceview-2.4.2.pet
valide-0.4-1-i686-svn-2009-03-27.pet
I run the vala-IDE by typing "validestart", or from the menu: "Valide -Puppy4"
Mark
Attachments
Timer.tar.gz
(3.32 KiB) Downloaded 792 times
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#67 Post by Lobster »

timer.c

Code: Select all

#include "timer.h"
#include <time.h>







char* getTime (void) {
	struct tm _tmp4 = {0};
	gint _tmp3_length1;
	gchar* _tmp3;
	time_t _tmp2 = {0};
	time_t _tmp0 = {0};
	struct tm _tmp1 = {0};
	char* _tmp5;
	_tmp3 = NULL;
	_tmp5 = NULL;
	return (_tmp5 = asctime_r ((_tmp4 = (localtime_r ((_tmp2 = (time (&_tmp0), _tmp0), &_tmp2), &_tmp1), _tmp1), &_tmp4), ((_tmp3 = g_new0 (gchar, 26)), _tmp3_length1 = 26, _tmp3)), (_tmp3 = (g_free (_tmp3), NULL)), _tmp5);
}


void _main (char** args, int args_length1) {
	char* _tmp0;
	GTimer* timer;
	/*-- display the current time --   */
	_tmp0 = NULL;
	g_print ("%s\n", (_tmp0 = getTime ()));
	_tmp0 = (g_free (_tmp0), NULL);
	/*-- run a timer to check how long a code needs --*/
	timer = g_timer_new ();
	g_timer_start (timer);
	{
		gint n;
		n = 0;
		for (; n <= 10000; n++) {
			g_print ("%d\n", n);
		}
	}
	g_timer_stop (timer);
	g_print ("%f seconds were needed.\n", g_timer_elapsed (timer, NULL));
	(timer == NULL ? NULL : (timer = (g_timer_destroy (timer), NULL)));
}


int main (int argc, char ** argv) {
	g_type_init ();
	_main (argv, argc);
	return 0;
}
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#68 Post by MU »

looks different then mine, though there is no strcmp.

do you use vala 0.5.7?
Please try, if my project from my former message works.

Code: Select all

#include "main.h"
#include <time.h>




static char* g_time_to_string (struct tm *self);



static char* g_time_to_string (struct tm *self) {
	return g_strdup_printf ("%04d-%02d-%02d %02d:%02d:%02d", (*self).tm_year + 1900, (*self).tm_mon + 1, (*self).tm_mday, (*self).tm_hour, (*self).tm_min, (*self).tm_sec);
}


char* getTime (void) {
	struct tm _tmp3 = {0};
	time_t _tmp2 = {0};
	time_t _tmp0 = {0};
	struct tm _tmp1 = {0};
	return g_time_to_string ((_tmp3 = (localtime_r ((_tmp2 = (time (&_tmp0), _tmp0), &_tmp2), &_tmp1), _tmp1), &_tmp3));
}


void _main (char** args, int args_length1) {
	char* _tmp0;
	GTimer* timer;
	/*-- display the current time --    */
	_tmp0 = NULL;
	g_print ("%s\n", _tmp0 = getTime ());
	_tmp0 = (g_free (_tmp0), NULL);
	/*-- run a timer to check how long a code needs -- */
	timer = g_timer_new ();
	g_timer_start (timer);
	{
		gint n;
		n = 0;
		for (; n <= 10000; n++) {
			g_print ("%d\n", n);
		}
	}
	g_timer_stop (timer);
	g_print ("%f seconds were needed.\n", g_timer_elapsed (timer, NULL));
	(timer == NULL) ? NULL : (timer = (g_timer_destroy (timer), NULL));
}


int main (int argc, char ** argv) {
	g_type_init ();
	_main (argv, argc);
	return 0;
}
Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#69 Post by Lobster »

do you use vala 0.5.7?
I use vala 0.5.1
0.5.7 had a major bug in it meaning that simple samples were not running
Barry reported it to the developers

OK gonna try 0.5.7 again . . .
For now I am not going to use valide . . .
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#70 Post by Lobster »

Or compile main.gs by hand:
valac main.gs
./main
upgraded here
http://dotpups.de/puppy4/dotpups/Programming/Vala/

timer now running
many thanks Mark

gonna check earlier code to see if it runs :)
Last edited by Lobster on Fri 27 Mar 2009, 13:33, edited 1 time in total.
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#71 Post by Lobster »

this code which was working is no longer compiling with the newer vala :cry:
http://www.murga-linux.com/puppy/viewto ... 981#286981

Code: Select all

# valac v14.gs
v14.gs:22.7-22.9: error: syntax error, expected end of line but got identifier with previous `else'
        else num = num + 96
             ^^^
v14.gs:51.7-51.11: error: syntax error, expected end of line but got `print' with previous `else'
        else print(USAGE)                                   /* this appears if program run without text */
             ^^^^^
Compilation failed: 2 error(s), 0 warning(s)
# 
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

MUguest
Posts: 73
Joined: Sat 09 Dec 2006, 16:40

#72 Post by MUguest »

the code after "else" must go to a new line.

Here is your updated code.
I also fixed two "print" statements to
print("%s" , thetext )

Mark

Code: Select all

// Infinite Monkey Theorem 
// Lobster and Shadow, March 2009 LGPL 

// use from command line 
// imt ["search text"] 
// generates random characters and searches for a given pattern eg 'in the beginning was the world' 
// warning strings longer than "in the" may take minutes or hours to find 

// program demonstrates: 
//   basic functions 
//   passing parameters in command line 
//   random character generation 
//   constant 
[indent=3]
def getRandomNumber(RangeFrom:int, RangeTo:int) : int  /* function to create random number between range */ 
   return GLib.Random.int_range(RangeFrom,RangeTo) 

def getRandomChar() : char                             /* function to generate ascii codes from a-z and space (32) */ 
   num:int = getRandomNumber(0,27) 
   if num == 0 
      num = 32 
   else
      num = num + 96 
   return (char) num 

def addRandomChar(myText:string) : string              /* function add text from command line */ 
   var retText = new StringBuilder 
   retText.append(myText) 
   retText.append_c(getRandomChar()) 
   return retText.str 
       
init 
   USAGE:string = "Usage:\n\t ./imt \"some text for monkeys to generate\" " 
   theText:string = args[1] 
   if theText == null 
      theText = "" 
   theText = theText.down()                            /* change any text input to lower case */    
   myText:string = "" 

   if theText != "" 
      do    
         do 
            myText = addRandomChar(myText) 
         while theText.len() != myText.len() 
              print("%s" , myText) 
         if theText != myText 
            stdout.printf("\n") 
            myText = "" 
      while theText != myText 
      stdout.printf("\n") 

   else
      print("%s" , USAGE)                                   /* this appears if program run without text */


User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#73 Post by Lobster »

the code after "else" must go to a new line.
ah - I think it was OK previously - that makes it much clearer
- now working :)
many thanks . . .
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#74 Post by Lobster »

after trying to install the gedit editor - and giving up after finding one missing library and then failing to find the other :?
I instead installed medit (in the v4 puppy package manager list)
or Aragon has compiled the latest version here
http://murga-linux.com/puppy/viewtopic. ... 467#272389

that seems OK and supports Vala - I have written to the developer about Genie support

Barry mentions this on his genie page
Limited editor/IDE support
That will improve pretty quickly I think. I whipped up basic color syntax highlighting for the Medit text editor
Has that been sent to the developers I wonder?

Very nice editor - immediately felt at home 8)

Still have not installed Valide (too dangerous)
but am keen to get GTK running

Code: Select all

[indent=4]
/* GTK+ Genie Sample Code - compile with valac --pkg gtk+-2.0 hello-gtk.gs */
uses 
    Gtk

init 
    Gtk.init (ref args)
    var test = new TestWindow ()
    test.show_all ()
    Gtk.main ();

class TestWindow : Window
    init
        title = "Test Window"
        default_height = 250
        default_width = 250
        window_position = WindowPosition.CENTER
        destroy += Gtk.main_quit
        var button = new Button.with_label ("Click Me")
        button.clicked += def (btn)
            title = "Hello World"
            btn.label = "Hello World"
        add (button)
which is giving me this misinformation
probably nothing to do with Arthur Dent . . .

Code: Select all

# valac v15_gtk_test.gs
v15_gtk_test.gs:22.15-22.14: error: syntax error, expected line end or semicolon but got `dedent'
                add (button)
                            
Compilation failed: 1 error(s), 0 warning(s)
# 
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#75 Post by BarryK »

Lobster,
Medit uses gtksourceview, but if I recall rightly it has it's own in-built gtksourceview.

The "proper" gtksourceview 2.4.2 pet pkg that I have provided has a file in it, 'genie.lang'. Um, let's see, it's at
/usr/share/gtksourceview-2.0/language-specs/

As Medit has it's own gtksourceview, you need to find where it keeps its .lang files, and copy 'genie.lang' in there, and then Medit should have genie syntax highlighting.
[url]https://bkhome.org/news/[/url]

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#76 Post by BarryK »

Lobster,
for the hello-gtk.gs, do you have a carriage-return on the last line?

I just tested, running Intrepid Puppy alpha3, devx loaded, I copied the example hello-gtk from my web page, pasted it into a file, compiled it with valac, it works.

Hmm, I took the carriage-return off the last line, it still compiles.

I have copied the code you posted to this thread, that compiles too.

I'm using Vala 0.5.7.
[url]https://bkhome.org/news/[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#77 Post by Lobster »

Many thanks Barry,

I am awaiting a page on GTK on your Genie pages :)
I have cautiously added Valide :shock:
and got a working hello world

There are good example GTK for Vala but not Genie on the Vala pages
Mark is already using Glade but I am still working up to crawl status
Lobster,
for the hello-gtk.gs, do you have a carriage-return on the last line?
Yes tried all that but it just must be that!
thanks will try again . . .

edit:
no luck and leafpad is not saving - valide strikes again . . .
gonna try another computer . .
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#78 Post by DMcCunney »

Lobster wrote:I instead installed medit

that seems OK and supports Vala - I have written to the developer about Genie support
AFAIK, Geany supports Vala.

File type support is defined in a file called filetypes.<name>, where <name> is the language name.

There is a filetypes.vala file in /usr/share/geany
______
Dennis

aragon
Posts: 1698
Joined: Mon 15 Oct 2007, 12:18
Location: Germany

#79 Post by aragon »

@ lobster

attached is the genie.lang from here:
http://bugzilla.gnome.org/show_bug.cgi?id=576141

if you're using my medit-package, extract it to

Code: Select all

/usr/share/moo/language-specs
and there you are.

aragon
Attachments
genie.lang_medit.tar.gz
(2.09 KiB) Downloaded 594 times

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#80 Post by Lobster »

Thanks guys
Thanks aragon
how about a free movie . . . violence and stuff . . . Blank
http://www.webtvwire.com/blank-movie-di ... ittorrent/
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

Post Reply