Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 28 Aug 2014, 05:26
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Vala and Genie programming
Post new topic   Reply to topic View previous topic :: View next topic
Page 5 of 35 [517 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7, ..., 33, 34, 35 Next
Author Message
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 23 Mar 2009, 12:38    Post subject:  

Code:
[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 Smile
Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Mon 23 Mar 2009, 12:55    Post subject:  

Quote:
And now eat some fish *mjam


never heard of that . . .
does it come with chips (fries)?

Thanks Mark
this is what I got
Code:
# valac timer.gs
# ./timer

Segmentation fault


probably need the rest of the week to figure it out now . ..

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 23 Mar 2009, 13:17    Post subject:  

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 Smile
Was gooood, although it was from the supermarket.

Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Mon 23 Mar 2009, 16:19    Post subject:  

Code:
(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 WIKI
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 23 Mar 2009, 20:59    Post subject:  

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

Then paste here timer.c.

Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Mon 23 Mar 2009, 22:35    Post subject:  

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
Timer.tar.gz
Description 
gz

 Download 
Filename  Timer.tar.gz 
Filesize  3.32 KB 
Downloaded  538 Time(s) 

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Mon 23 Mar 2009, 23:50    Post subject:  

timer.c

Code:

#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 WIKI
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Tue 24 Mar 2009, 02:47    Post subject:  

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:

#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

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Tue 24 Mar 2009, 04:09    Post subject:  

Quote:
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 WIKI
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Tue 24 Mar 2009, 06:32    Post subject:  

Quote:
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 Smile

_________________
Puppy WIKI

Last edited by Lobster on Fri 27 Mar 2009, 09:33; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Tue 24 Mar 2009, 07:33    Post subject:  

this code which was working is no longer compiling with the newer vala Crying or Very sad
http://www.murga-linux.com/puppy/viewtopic.php?p=286981#286981

Code:
# 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 WIKI
Back to top
View user's profile Send private message Visit poster's website 
MUguest

Joined: 09 Dec 2006
Posts: 73

PostPosted: Tue 24 Mar 2009, 09:00    Post subject:  

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:
// 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 */

Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Tue 24 Mar 2009, 09:36    Post subject:  

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


ah - I think it was OK previously - that makes it much clearer
- now working Smile
many thanks . . .

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Wed 25 Mar 2009, 07:39    Post subject:  

after trying to install the gedit editor - and giving up after finding one missing library and then failing to find the other Confused
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.php?p=272389&search_id=1599208467#272389

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

Barry mentions this on his genie page
Quote:
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 Cool

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


Code:
[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:
# 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 WIKI
Back to top
View user's profile Send private message Visit poster's website 
BarryK
Puppy Master


Joined: 09 May 2005
Posts: 7047
Location: Perth, Western Australia

PostPosted: Wed 25 Mar 2009, 08:59    Post subject:  

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.

_________________
http://bkhome.org/news/
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 5 of 35 [517 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6, 7, ..., 33, 34, 35 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1156s ][ Queries: 13 (0.0097s) ][ GZIP on ]