It is currently Wed Sep 08, 2010 12:59 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Functions - an example
PostPosted: Tue Mar 23, 2010 10:54 pm 

Joined: Sat Apr 12, 2008 10:05 pm
Posts: 34
Here is an example how you can use 'functions' in the ds-script. It should be possible to write a parser in the ds-script so you can use simpler code in your code for functions and then run parser to convert it to the ds-script.

Code:
//START - the main function
@Main
   // Call function Bar2
   $ret = bar2_main   // Store return point
   goto bar2      // Call the function
   @bar2_main      // Return point

   // Call function Bar1
   $ret = bar1_main   // Store return point (pass it to the called function)
   goto bar1      // Call the function
   @bar1_main      // Return point
   
   // Finish
   goto end      // Jump to the end
//END


//FUNCTIONS:

//Function Foo
@foo
   $foo_ret = $ret            //Store return point in case we want to call other function

   // Here is function Foo main code

      SAY Foo function launched.

   // End of function Foo main code

   goto $foo_ret



//Function Bar1
@bar1
   $bar1_ret = $ret         //Store return point in case we want to call other function

   // Here is function Bar1 main code

      SAY Function Bar1 launched

      // Call function Foo
      $ret = foo_bar1         // Store return point (pass it to the called function)
      goto foo         // Call the function
      @foo_bar1         // Return point

   // End of function Bar1 main code

GOTO $bar1_ret



//Function Bar2
@bar2
   $bar2_ret = $ret         //Store return point in case we want to call other function

   // Here is function Bar2 main code

      SAY Function Bar2 launched

      // Call function Foo   
      $ret = foo_bar2         // Store return point (pass it to the called function)
      goto foo         // Call the function
      @foo_bar2         // Return point

   // End of function Bar1 main code

GOTO $bar2_ret

@end


The parser should allow you to write something like...
Code:

call bar1()
call bar2()
goto end

function foo()
{
SAY This is foo function.
}

function bar1()
{
SAY This is bar1 function
call foo()
}

function bar2()
{
SAY This is bar2 function
call foo()
}

@end

... and then convert it to above example.

It should move ds-script to the new level. You can of course add support for function arguments as well - should be easy.

_________________
Meteoryty, tektyty, astronomia:
[url]meteoryty.sklepna5.pl[/url]


Offline
 Profile  
 
 Post subject: Re: Functions - an example
PostPosted: Wed Mar 24, 2010 12:37 am 
User avatar

Joined: Thu Mar 27, 2008 8:51 pm
Posts: 395
Location: Hertfordshire, United Kingdom
That's similar to a group of scripts i made, Jinx Framework, these scripts can be called, with parameters, and return data, or create graphics on the screen, depending on parameters...

One of them was a Menu script, which takes pre-set parameters, and displays a menu on the screen with a built in event handler, the code needed in the users script was only about 5-10 lines...
The only issue with the Jinx Framework is that anyone who runs the script needs to have the Jinx Framework installed for it to work, host and client...

I like the idea of a script parser, but that could be a very large script, and i think it has been tryed, but failed since it was VERY slow... plus it would have the same issue as the Jinx Framework, everyone would need to have it installed for it to work...

I have been coming up with certain ways of creating script code automatically, and then "Streaming" it from a domain, and running it on the client-side, but this is quite hard to get around as DSO has a very unstable script-engine.

_________________
DSO - More than just a hacking simulator!

Mess with the best, Die like the rest!


Offline
 Profile  
 
 Post subject: Re: Functions - an example
PostPosted: Wed Mar 24, 2010 8:13 pm 

Joined: Sat Apr 12, 2008 10:05 pm
Posts: 34
The parser could work as an compiler so after you process the script with functions you will get normal ds-script that can be shared with others who don't have this 'compiler'. In this way it only takes time to compile it but running should be fast.

Actually this compiler would have to use stack instead of just variables (register like) to handle situation when the same function is called.

When I will have some time I am going to write it...

_________________
Meteoryty, tektyty, astronomia:
[url]meteoryty.sklepna5.pl[/url]


Offline
 Profile  
 
 Post subject: Re: Functions - an example
PostPosted: Sat Apr 24, 2010 4:53 pm 

Joined: Fri Jun 19, 2009 1:18 pm
Posts: 38
you can create a kind of stack using
Code:
// 'declaration' of the stack
$pointer = 0

// push an item into the stack
$stackName[$pointer] = <your content of the stack item>
$pointer = $pointer + 1

// pop an item from the stack
$pointer = $pointer - 1
$item = $stackName[$pointer]


If you created such an 'compiler' please let me know it's looking really nice... ;)


Offline
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


 Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
 
cron