Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SilverScript: New scripting language for game development  (Read 15063 times)

0 Members and 1 Guest are viewing this topic.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Re: SilverScript: New scripting languages for game development
« Reply #15 on: December 19, 2012, 04:57:55 pm »
Using ref introduces an expectancy that you can get references to variables, which I don't know if you want SilverScript to support or not.
Actually I'm not supporting references/pointers in SilverScript. The only usual way to pass "references" of for example Integers is packing them to a Class, as they are always referenced, if not creating a new instance of it (cloning).

When referencing a function via the ref-keyword, I want be able to change the reference variable (that points to the original function) without affecting the original variable, and then the ref-keyword can't work for numeric variables.
Please note that my previous display name was "Shy Guy".

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Re: SilverScript: New scripting languages for game development
« Reply #16 on: January 05, 2013, 12:42:09 pm »
Hi, it's me again. There are two things to say:

1. I'm still actively working on SilverScript. I've been rewriting the parser code, so that it is more efficient and that it now generates an Abstract Syntax Tree, which wasn't there before. This makes it for example easier to optimize script code (for example calculating expressions, of constants only, to the final value on the fly).

2. There are still many things, that aren't finally decided yet. I'm developing SilverScript to be used in my personal projects, but I want to make SilverScript's source code available so that any of you could use it in their projects as well, so your suggestions on the language design might be helpful.
Note that SilverScript is designed to be embedded in games (e.g. written in C++), but I'm planning to add the feature that one could write applications based on SilverScript (runned by the main interpreter executable) and extended, for example by DLLs. Here come the questions I have to you, please tell me, what you like best:

  • SilverScript has got a global "namespace", which can be directly accessed from anywhere (classes, functions, ...) through the global namespace (e.g. global.foobar). I saw that Ruby uses the $-prefix for global variables. Would you like to have the $-prefix as a synonym for global.?
  • Should it be possible that classes have private, or even protected members?
  • What about virtual methods? (class inheritance is already planned)
  • Would you prefer the last expression of a function always being the default return value, or would you only allow explicit return values with the return keyword?
  • What do you think about "everything is an expression"? For example, should this be possible?: x = if y > 0 then true else false
  • What do you think about the idea, that any number of parameters can be passed to a function, no matter how many are specified? Non-passed parameters are initialized as nil (or their default value).
  • When passing more parameters to a function as specified, how would you like to access the additional parameters? (compare with vargs and printf-like functions in C)
  • In syntax, while-loops look like if-loops, just with a different keywords. Which other loops would you like to have (such as for), and how to design it?
  • What do you think about the distinction between Integer and Decimal in my language? Types are dynamic, though.
  • What should count as "false"? Only nil and false? Or also 0? What about "empty" classes and arrays?
Thanks in advance in supporting me :)
Please note that my previous display name was "Shy Guy".

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SilverScript: New scripting languages for game development
« Reply #17 on: January 05, 2013, 01:47:08 pm »
Quote from: Shy Guy
I saw that Ruby uses the $-prefix for global variables. Would you like to have the $-prefix as a synonym for global.?
I don't know how often this specific feature would be used, but in general, I would tend to not offer everything in multiple variations only to make everyone happy. It may easily cause confusion, if it's not clear that there are no differences.

Quote from: Shy Guy
Should it be possible that classes have private, or even protected members?
What about virtual methods? (class inheritance is already planned)
This depends on how complex you want the language to be. Should it be a simple script language for configurations and AI scripts or similar? Or do you want a full-fledged interpreted language with OOP language features?

I personally would keep things simple for the moment, and make sure they run stable, bug-free and efficient. You can still add more features later. But for complex OOP designs, statically typed languages scale better -- while script languages are useful to manage the dynamic parts, or configurations.

Quote from: Shy Guy
Would you prefer the last expression of a function always being the default return value, or would you only allow explicit return values with the return keyword?
What if there are multiple places to leave a function? I would prefer return statements.

Quote from: Shy Guy
What do you think about "everything is an expression"? For example, should this be possible?: x = if y > 0 then true else false
Basically an interesting idea, but can it be applied to everything? What's the expression of a loop? Of a function call that returns nothing? In this specific case, you could also use something like operator?: :P

Quote from: Shy Guy
What do you think about the idea, that any number of parameters can be passed to a function, no matter how many are specified? Non-passed parameters are initialized as nil (or their default value).
You lose type safety by doing so and introduce the need to check for validity of function parameters. However, there could be a way to pass multiple parameters to functions (in an array/list or something).

Quote from: Shy Guy
When passing more parameters to a function as specified, how would you like to access the additional parameters? (compare with vargs and printf-like functions in C)
As stated, a list or something similar might be the way. Do you have such a data structure which is built-in to your language?

Quote from: Shy Guy
In syntax, while-loops look like if-loops, just with a different keywords. Which other loops would you like to have (such as for), and how to design it?
If-statements are no loops, they are executed at most once. The for loop should definitely be available, its design depends on other language features. Do you have something like intervals or ranges?

Also, a foreach loop would be very handy.

Quote from: Shy Guy
What do you think about the distinction between Integer and Decimal in my language? Types are dynamic, though.
The distinction is a good idea, it allows to check more easily for valid index access, for example.

Quote from: Shy Guy
What should count as "false"? Only nil and false? Or also 0? What about "empty" classes and arrays?
What does "count as false" mean? Inside if statements? What I wouldn't do is the ambiguity that if (xy) is true if xy is valid or true. I would allow only boolean statements in conditions, and provide something else to check for the existence or validity of a variable, maybe an additional operator like if (#xy).

Do you differ between existence (variable has been assigned a value) and validity (variable is not nil)? If so, is it possible to "undeclare"/delete a variable, such that it becomes inexistent?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Re: SilverScript: New scripting languages for game development
« Reply #18 on: January 05, 2013, 03:11:37 pm »

Quote from: Shy Guy
Would you prefer the last expression of a function always being the default return value, or would you only allow explicit return values with the return keyword?
What if there are multiple places to leave a function? I would prefer return statements.

Quote from: Shy Guy
What do you think about "everything is an expression"? For example, should this be possible?: x = if y > 0 then true else false
Basically an interesting idea, but can it be applied to everything? What's the expression of a loop? Of a function call that returns nothing? In this specific case, you could also use something like operator?: :P
Just the last expression of a function would be returned, if nothing else was explicitly returned with the return-keyword. Things like a loop could simply return nil (i.e. "no" value). This is also the default value for uninitialized variables, variables which aren't assigned to any (other) value yet.



Quote from: Shy Guy
When passing more parameters to a function as specified, how would you like to access the additional parameters? (compare with vargs and printf-like functions in C)
As stated, a list or something similar might be the way. Do you have such a data structure which is built-in to your language?

Quote from: Shy Guy
In syntax, while-loops look like if-loops, just with a different keywords. Which other loops would you like to have (such as for), and how to design it?
If-statements are no loops, they are executed at most once. The for loop should definitely be available, its design depends on other language features. Do you have something like intervals or ranges?

Also, a foreach loop would be very handy.
Yeah, I would like to make foreach loop possible. The current "interval" data type in SilverScript is the array, but I was thinking of arrays not having a specific "size" (any index out or range simply is nil and could be assigned to any value; index mustn't be negative or a decimal number).

Just another note: first I wanted the array being a data type itself. If you have a variable number of items stored in it (instead of simply 2, or 17 or another static value), you have to store the size in a separate variable, as 1. the array does not really have a size visible to the programmer and 2. neither there's (yet) a "size"-operator, nor I could provide a "size"-method, because any attribute access (with the dot .) would convert the array back to an object.
But I've got a new idea: an array is not a data type itself, but instead it is just an object. Any object can have attributes/methods (which have names/identifiers), but also have, let's say, "unnamed" attributes, accessed by their indices, accessed with the []-brackets.



Quote from: Shy Guy
What should count as "false"? Only nil and false? Or also 0? What about "empty" classes and arrays?
What does "count as false" mean? Inside if statements? What I wouldn't do is the ambiguity that if (xy) is true if xy is valid or true. I would allow only boolean statements in conditions, and provide something else to check for the existence or validity of a variable, maybe an additional operator like if (#xy).

Do you differ between existence (variable has been assigned a value) and validity (variable is not nil)? If so, is it possible to "undeclare"/delete a variable, such that it becomes inexistent?
I especially mean in conditions.
Actually, there isn't yet a way to check a variable's existence (hence a variable assigned to nil, the default value, then "exists"), although the "existince" of a variable is important in another aspect of my language... a special operator for checking a variable's existince is a good idea, let me think... the hash (#) is already used for comments, but there are some other symbols left, I could use:
  • the exclamation mark (!); the logical not is expressed only by the not-keyword
  • the dollar sign ($), if not used for global variables besides "global."
  • the ampersand character (&)
  • maybe a unary *
  • or: ? : ^ ` ~
Please note that my previous display name was "Shy Guy".

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
About Arrays, Ranges and Objects
« Reply #19 on: February 18, 2013, 06:21:07 pm »
It's me again. I got back on developing on SilverScript and my Parser (which generates the abstract syntax tree) already works very well. Now there come some more questions about the language design, and I rely on your opinions.

In SilverScript, literal Arrays are possible. Conside the following code:
foobar = ["First Element", "Second Element", ...]
# is the same as:
foobar[0] = "First Element"
foobar[1] = "Second Element"
foonar[...] = ...


Classes (you may also call them Objects at this point) are some kind of simple containers: it contains identifiers which refer to some numbers ("attributes") or some functions ("methods") and are accessed with the dot (.). Example:
# assuming foo being a class/object
foo.bar = 27


First I wanted Class and Array being two different data types. But maybe they could both be the same data type (an Object)? I mean, foo can have an attribute (foo.bar) and an index (foo[12]) at the same time. In any case, should an Array and a class always be initialized explicitely? (i.e., foo[12] or foo.bar throws an error if foo isn't an Array/Class/Object yet)


I think, Ranges could be a handy thing in programming, so I was thinking of implementing Ranges. They are useful to extract substrings or a piece of items from an array. Consider the following example:
# assuming foobar being a string or array
foobar[0] # access the first char/item
foobar[0..4] # from-to (inclusive): access the first 4 chars/items (0, 1, 2, 3, 4)
foobar[0...4] # from-to (exclusive): access the first 3 chars/items (0, 1, 2, 3)
foobar[0,4] # from-length: access the first 4 chars/items
foobar[1,] # access everything without the first char/item
foobar[,4] # access the last 4 chars/items


Instead of the pure literals to access the items (like in the example above), the user may also use identifiers:
foobar[from..to]
foobar[start,length]
foobar[my_range]

As you can see in the third line, the brackets [] shouldn't be necessary for ranges. You could write:
my_range = 1..5
Even if I would make the brackets required, I've got problems with the special ranges expressed with [start,len], [start,] and [,len], as especially the first one could also be interpreted as an array with the elements start and len, which isn't the same as a Range (yes, I want Range and Array/Object being different data types).

Do you have any ideas on the design at this points? Any opinions and suggestions are greatly welcome :)
Please note that my previous display name was "Shy Guy".

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: About Arrays, Ranges and Objects
« Reply #20 on: February 18, 2013, 07:54:32 pm »
First I wanted Class and Array being two different data types. But maybe they could both be the same data type (an Object)? I mean, foo can have an attribute (foo.bar) and an index (foo[12]) at the same time.
Hm, what's the use case for something that's an array and a class at the same time? I mean, wouldn't it be clearer to take a class that contains an array in such situations?

Something you could also think about are maps/dictionaries. One possibility is to unify everything (array, object, map) like the tables in Lua. I have not worked a lot with them yet, so I don't know how well this works in practice. One thing you have to consider is that the more dynamic and interchangeable your types become, the more easily they are confused and type errors occur.

In any case, should an Array and a class always be initialized explicitely? (i.e., foo[12] or foo.bar throws an error if foo isn't an Array/Class/Object yet)
I would enforce an initialization. When you don't have strict scope and lifetime rules, there may still be an old object with the same name, and one accidentally reuses it.

I think, Ranges could be a handy thing in programming, so I was thinking of implementing Ranges.
Sounds like a good idea! However, I would take the .. operator for half-open intervals, as this case appears more often. Especially when your indices start at 0, you will often have intervals of the form begin..arraysize. From my own experience, the way how the STL does it is very intuitive and doesn't require off-by-one corrections (+1 or -1).

Even if I would make the brackets required, I've got problems with the special ranges [...]
Why don't you take curly braces for arrays, like a = {1,2,3}?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Re: About Arrays, Ranges and Objects
« Reply #21 on: February 18, 2013, 08:28:12 pm »
Hm, what's the use case for something that's an array and a class at the same time? I mean, wouldn't it be clearer to take a class that contains an array in such situations?

Something you could also think about are maps/dictionaries. One possibility is to unify everything (array, object, map) like the tables in Lua. I have not worked a lot with them yet, so I don't know how well this works in practice. One thing you have to consider is that the more dynamic and interchangeable your types become, the more easily they are confused and type errors occur.
Taking a class containing an array might mean, that the user could implement an array class himself, too. And if the access works with the []-brackets, SilverScript should have some kind of operator overloading, and I have no clear plans yet how to design operator overloading methods.
Nonetheless I'm going to have Arrays (with indices 0, 1, 2, ...) and Maps/Hash Tables. Maps will only allow strings as keys, just to permit the use of something like an object as a key (there isn't a clear definition about object comparison behavior, yet).

I would enforce an initialization. When you don't have strict scope and lifetime rules, there may still be an old object with the same name, and one accidentally reuses it.
SilverScript has very local variables, similar to the principle in PHP with the functions. Variables from an outer namespace are to be accessed explicitly.

I think, Ranges could be a handy thing in programming, so I was thinking of implementing Ranges.
Sounds like a good idea! However, I would take the .. operator for half-open intervals, as this case appears more often. Especially when your indices start at 0, you will often have intervals of the form begin..arraysize. From my own experience, the way how the STL does it is very intuitive and doesn't require off-by-one corrections (+1 or -1).
Could you show me examples / explain in detail? I have never worked with Ranges yet, I just saw that feature in Python and Ruby on the fly.

Why don't you take curly braces for arrays, like a = {1,2,3}?
I was thinking about something like that, too. But: {} for arrays and [] for ranges? Or vice-versa? And what about literal hash tables? Here is what I was thinking so far at the moment:
my_array = [ "First Item", "Second Item", "You may also use other types:", 27.5, [ "SubArray", ... ] ]
my_hash = [ "Name" => "John Doe", "Location" => "USA", "Age" => 22 ]
class my_object # the same as: my_object = class
  x = 0
  y = 0
end
# what about the following additional syntax for literal objects?
my_object2 = { x = 0, y = 0 }
my_range1 = [0..3]
my_range2 = [5,2] # <-- would be interpreted as an array.....
Please note that my previous display name was "Shy Guy".

greeniekin

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: SilverScript: New scripting language for game development
« Reply #22 on: February 21, 2013, 09:23:56 am »
I like some aspects of this. Like simi-colons are a bit nasty when it is bad form not to have and enter after the line. Why not just have a new line and that's it. I have done a lot of programming in javascript and dynamic types can be nice sometimes.

I still, like everyone else, thinks functions should have brackets. It makes things more clear.

Not having braces seems personally weird. I use to program in qbasic and then visual basic. Though i have been doing so much work in php, javascript, and c++ that it just seems weird. I do get it though. Indentation is an important part of making something readable.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Re: SilverScript: New scripting language for game development
« Reply #23 on: July 09, 2013, 10:14:12 pm »
Update

After a long break I continued the development of SilverScript. In addition, the language design got some minor and major changes:
  • Variables are not created (declared) implicitly. You always have to declare new variables with the @-character (@foobar); it can be compared with the local keyword in other languages
  • The variable's data type can't be changed implicitly (e.g., foobar[2] does not convert foobar into an array, if it isn't already one)
  • New class instances are created with the new keyword rather than by just calling its new method directly (before: inst = foobar.new(); now: inst = new foobar())
  • Class inheritance is fully supported (in theory). Base class methods and attributes can be accessed by the child class even if the child has overwritten the methods/attributes, i.e. the child class can call the base's constructor for example. Static class attributes might be possible too...
  • The VirtualMachine (interpreter) will have a garbage collector, to avoid the cyclic reference problem.
  • Function calls: parantheses (around the parameters, if available) are required, not optional.
  • Functions: parameters can have a default value or even marked as optional; additional parameters can be passed and accessed by the function, similar to C's printf() function
  • Generators are planned, so that they can be used in a foreach structur for example
The license for the first release might be LGPL, but it's propable to become zlib in a later version when SilverScript is matured.


EDIT: I forgot to show you what the C++ API is going to look like. Here a short example snippet:
#include <iostream>
#include <SilverScript.h>

using namespace std;

int main()
{
  sil::VM vm; // the virtual machine; it is initialized automatically
 
  // load a script and pack it in a callable function object
  sil::Object func = vm.loadFromFile("test.sil");
 
  // check whether script was loaded successfully
  if(!func.isNil())
  {
    sil::Object result = func.call(); // call script and get return value
    cout << "Result: " << result.toInteger() << endl;
  }
 
  return 0;
}
« Last Edit: September 29, 2013, 06:23:04 pm by Shy Guy »
Please note that my previous display name was "Shy Guy".

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SilverScript: New scripting language for game development
« Reply #24 on: July 09, 2013, 11:38:52 pm »
The changes sound good, nice to see you applied some of the suggestions from this thread :)

By the way, what tools do you use for the implementation? Just standard C++? Or a parser framework like Boost.Spirit?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
Re: SilverScript: New scripting language for game development
« Reply #25 on: July 09, 2013, 11:45:33 pm »
By the way, what tools do you use for the implementation? Just standard C++? Or a parser framework like Boost.Spirit?
I'm only using the new C++11 standard, including some of its new headers and classes. I might try to make a portable version not using the new C++ as well. In addition I plan to provide a version for C, too.
Please note that my previous display name was "Shy Guy".

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
SilverScript: Concept of Modules
« Reply #26 on: October 02, 2013, 03:53:14 pm »
Like in any other programming and scripting language there shall also be the possibility in SilverScript to put the code in several files for better overview and maintenance. So I am thinking about the concept of so called modules.

Let's say, you have got your main script file main.sil, and you define a class for creating a window in window.sil.

window.sil (1):
class window
  # attributes and class methods
end


main.sil:
use window # the interpreter looks for window.sil and loads it into the "window" namespace/class
@my_window = new window.window()



Note that you can give modules, you import, any alias you want:
use window as w
@my_window = new w.window()



There are also cases, where you want to load a module directly into the current namespace. This is supported through the keyword import:
import window
@my_window = new window()



If your module only has got a single class, you can also trick there a little bit and treat the module as a class:
window.sil (2):
@window_attribute1 = 0
@window_attribute2 = 0

# ...

function new() # constructor
  # initialize a new instance
end

# more class members...



main.sil:

use window
use window as foobar

@first_window = new window()
@second_window = new foobar()




Please tell me your oppinions and suggestions about these plans. Do you have any improvements?
It is not clear yet, where the module files (when using/importing a module the first time) are searched and in which order, but they shall be searched at least in the directory where the requesting script file lies.
Please note that my previous display name was "Shy Guy".

 

anything