Indexed by TopGit from live GitHub metadata: crossoverJie/gscript has 222 stars, written primarily in Go. 💪🏻This is a statically and strongly typed language written in Go.|GScript 是用 Go 编写的静态、强类型的脚本语言。
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
This is a statically and strongly typed language written in Go, the syntax of Java and Go is referenced.
Target
Provides the ability to write Go language in script form, retains the advantages of Go language (goroutine, etc.), and adds more syntactic sugar for ease of use.
The current Alpha version is for study and experimentation only.
func int() fib(){
int a = 0;
int b = 1;
int fibonacci(){
int c = a;
a = b;
b = a+c;
return c;
}
return fibonacci;
}
func int() f = fib();
for (int i = 0; i < 10; i++){
println(f());
}
Webapp
This is a dynamic web application written in GScript.
// Declare and initialize
int[] a={1,2,3};
println(a);
// Declare an empty array and specify the length
int[] table = [4]{};
println("");
// Append data to array.
append(a,4);
println(a);
for(int i=0;i<len(a);i++){
println(a[i]);
}
// Access to data by index.
int b=a[2];
println(b);
// byte array
string s = "10";
byte[] a= toByteArray(s);
printf("a=%v ",a);
string s1 = toString(a);
printf("s1=%s",s1);
assertEqual(s1,s);
// slice an array into a new array.
int[] a = {1,2,3};
int s=1;
int[] b = a[s:len(a)];
println(b);
// output: [2 3]
any type
An any type may hold values of all type.
any a =10;
println(a);
int fun1(any a,int b){
return a+b;
}
int v =fun1(1,2);
println(v);
assertEqual(v,3);
any v2 = fun1(1,2);
println(v2);
assertEqual(v2,3);
int fun2(int a, any b){
return a+b;
}
int v3 =fun2(1,2);
println(v3);
assertEqual(v3,3);
int fun3(any a, any b){
return a+b;
}
int v4 =fun3(1,2);
println(v4);
assertEqual(v4,3);
int fun4(any a, any b){
return a+b;
}
string v5 =fun4("10", "20");
println(v5);
assertEqual(v5,"1020");
Example: Standard library
Class
class ListNode{
int value;
ListNode next;
ListNode(int v, ListNode n){
value =v;
next = n;
}
}
// The new keyword is not required to call the constructor.
ListNode l1 = ListNode(1, nil);
// Using . to access object property or method.
println(l1.value);
The default comes with a parameterless constructor
class Person{
int age=10;
string name="abc";
int getAge(){
return 100+age;
}
}
// parameterless constructor
Person xx= Person();
println(xx.age);
assertEqual(xx.age, 10);
println(xx.getAge());
assertEqual(xx.getAge(), 110);
int add(string s, int ...num){
println(s);
int sum = 0;
for(int i=0;i<len(num);i++){
int v = num[i];
sum = sum+v;
}
return sum;
}
int x = add("abc", 1,2,3,4);
println(x);
assertEqual(x, 10);
Operator overloading
Operator that Gscript support:
+-*/
== != < <= > >=
Overloading function must be operator, and append operator.
class Person{
int age;
Person(int a){
age = a;
}
}
Person operator + (Person p1, Person p2){
Person pp = Person(p1.age+p2.age);
return pp;
}
Person operator - (Person p1, Person p2){
Person pp = Person(p1.age-p2.age);
return pp;
}
Person operator * (Person p1, Person p2){
Person pp = Person(p1.age * p2.age);
return pp;
}
Person operator / (Person p1, Person p2){
Person pp = Person(p1.age / p2.age);
return pp;
}
bool operator == (Person p1, Person p2){
return p1.age==p2.age;
}
bool operator != (Person p1, Person p2){
return p1.age!=p2.age;
}
bool operator > (Person p1, Person p2){
return p1.age>p2.age;
}
bool operator >= (Person p1, Person p2){
return p1.age>=p2.age;
}
bool operator < (Person p1, Person p2){
return p1.age<p2.age;
}
bool operator <= (Person p1, Person p2){
return p1.age<=p2.age;
}
Person p1 = Person(10);
Person p2 = Person(20);
//Person p3 = operator(p1,p2);
Person p3 = p1+p2;
println("p3.age="+p3.age);
assertEqual(p3.age, 30);
Person p4 = p1-p2;
println("p4.age="+p4.age);
println(100-10);
Person p5 = p1*p2;
println("p5.age="+p5.age);
assertEqual(p5.age, 200);
Person p6 = p2/p1;
println("p6.age="+p6.age);
assertEqual(p6.age, 2);
bool b1 = p1 == p2;
println("b1=="+b1);
assertEqual(b1,false);
bool b2 = p1 != p2;
println("b2=="+b2);
assertEqual(b2,true);
bool b3 = p1 > p2;
println("b3=="+b3);
assertEqual(b3,false);
bool b4 = p1 >= p2;
println("b4=="+b4);
assertEqual(b4,false);
bool b5 = p1 < p2;
println("b5=="+b5);
assertEqual(b5,true);
bool b6 = p1 <= p2;
println("b6=="+b6);
assertEqual(b6,true);
More examples: https://github.com/crossoverJie/gscript/tree/main/example
Standard library
Standard library source code: https://github.com/crossoverJie/gscript/tree/main/internal
Native function
printf("hello %s ","123");
printf("hello-%s-%s ","123","abc");
printf("hello-%s-%d ","123",123);
string s = sprintf("nice to meet %s", "you");
println(s);
assertEqual(s,"nice to meet you");
int[] a={1,2,3};
// len return array length.
println(len(a));
// Append data to array.
append(a,4);
println(a);
// output: [1,2,3,4]
// Assert function
assertEqual(len(a),4);
// Return hashcode
int hashcode = hash(key);
// Serialize to JSON string.
class P{
string name;
P(string n){
name = n;
}
}
class Object{
P p;
int x;
Object(P pp, int xx){
p = pp;
x = xx;
}
}
P p1 = P("abc");
Object o1 = Object(p1, 100);
string json = JSON(o1);
println(json); //{"p":{"name":"abc"},"x":100}
// Query json with path
int x = JSONGet(json,"x");
println(x);
assertEqual(x,100);
string name = JSONGet(json,"p.name");
println(name);
assertEqual(name,"abc");
// Get command-line arguments.
System s = System();
string[] args = s.getOSArgs();
Reference JSON query syntax: xjson
Map
Function Definition
class Map{
put(any key, any value){}
any get(any key){}
}
Usage
int count =100;
Map m1 = Map();
for (int i=0;i<count;i++){
string key = i+"";
string value = key;
m1.put(key,value);
}
println(m1.getSize());
assertEqual(m1.getSize(),count);
for (int i=0;i<count;i++){
string key = i+"";
string value = m1.get(key);
println("key="+key+ ":"+ value);
assertEqual(key,value);
}
StringBuilder
Function Definition
class StringBuilder{
byte[] buf = [0]{};
// append contents to buf, it returns the length of s
int writeString(string s){}
// append b to buf, it returns the length of b.
int WriteBytes(byte[] b){}
// copies the buffer to a new.
grow(int n){}
string String(){}
}
Usage
StringBuilder b = StringBuilder();
b.writeString("10");
b.writeString("20");
int l = b.writeString("30");
string s = b.String();
printf("s:%s, len=%d ",s,l);
assertEqual(s,"102030");
byte[] b2 = toByteArray("40");
b.WriteBytes(b2);
s = b.String();
assertEqual(s,"10203040");
println(s);
Strings
Function Definition
class Strings{
// concatenates the elements of its first argument to create a single string. The separator
// string sep is placed between elements in the resulting string.
string join(string[] elems, string sep){}
// tests whether the string s begins with prefix.
bool hasPrefix(string s, string prefix){}
}
Usage
Strings s = Strings();
string[] elems = {"name=xxx","age=xx"};
string ret = s.join(elems, "&");
println(ret);
assertEqual(ret, "name=xxx&age=xx");
bool b = s.hasPrefix("http://www.xx.com", "http");
println(b);
assertEqual(b,true);
b = s.hasPrefix("http://www.xx.com", "https");
println(b);
assertEqual(b,false);
How active is development on crossoverJie/gscript?
The most recent commit recorded on crossoverJie/gscript was 4.0 years ago, based on the GitHub push timestamp. The repository has 25 forks — one of the better signals of community interest.
Is crossoverJie/gscript open source?
Yes — crossoverJie/gscript ships under the BSD-3-Clause license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/crossoverJie/gscript.
What license does crossoverJie/gscript use?
crossoverJie/gscript is released under the BSD-3-Clause license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
What topics is crossoverJie/gscript associated with?
GitHub's repository topics for crossoverJie/gscript: "antlr4", "compile", "go", "golang", "language", "programming-language". TopGit's editorial category is Backend.
Where can I see crossoverJie/gscript in action?
The project maintains a homepage at https://gscript.crossoverjie.top/. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about crossoverJie/gscript?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/crossoverJie/gscript is the definitive source.
Read full README in the tab above.
Still deciding about gscript?
One click hands the question to an AI along with this page — see what it says about gscript.