Skip to content

Commit c2f4d4c

Browse files
committed
add a readme
1 parent 6708d1b commit c2f4d4c

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Starscript.Net
2+
3+
[![NuGet Version](https://img.shields.io/nuget/v/Starscript.Net)](https://www.nuget.org/packages/Starscript.Net/)
4+
[![NuGet Downloads](https://img.shields.io/nuget/dt/Starscript.Net)](https://www.nuget.org/packages/Starscript.Net/)
5+
6+
Fast text formatting language for C#. This is a .NET port of [starscript by MeteorDevelopment](https://github.com/MeteorDevelopment/starscript/), written in Java.
7+
Licensed under MIT.
8+
9+
- Lightweight; No dependencies. Just .NET 9.
10+
- Standard operators: + - * / % ^
11+
- Ability to call functions defined in C#
12+
- Variables can be different each time they are used
13+
- Conditional output (ternary operator)
14+
- Variables can be maps
15+
16+
## Examples
17+
- `Hello {name}!`
18+
- `Number: {someNumber * 100}`
19+
- `FPS: {round(fps)}`
20+
- `Today is a {good ? 'good' : 'bad'} day`
21+
- `Name: {user.name}`
22+
23+
## Usage:
24+
You can find the latest version number at the top of this README. With that:
25+
26+
Your .csproj:
27+
```xml
28+
<PackageReference Include="Starscript.Net" Version="{version}" />
29+
```
30+
31+
32+
In your code:
33+
```csharp
34+
using Starscript;
35+
36+
// Parse
37+
if (!Parser.TryParse(@"Hello {name}! Starscript was originally created by {originalAuthor()}", out Parser.Result result))
38+
{
39+
foreach (var error in result.Errors)
40+
Console.WriteLine(error);
41+
42+
return;
43+
}
44+
45+
// Compile
46+
Script script = Compiler.SingleCompile(result);
47+
// The compiler also has the ability to batch compile and directly compile from source (throwing a ParseException if any errors are present)
48+
49+
// Create Starscript hypervisor instance
50+
StarscriptHypervisor hv = StarscriptHypervisor.Create()
51+
.WithStandardLibrary(); // Adds the default functions, not required
52+
53+
hv.Set("name", () => "GreemDev"); // dynamic variable
54+
hv.Set("originalAuthor", _ => "MineGame159"); // function
55+
56+
// Run
57+
Console.WriteLine(hv.Run(script));
58+
// or...
59+
Console.WriteLine(script.Execute(hv));
60+
```

Starscript.Net.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starscript.Net.Tests", "src
66
EndProject
77
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starscript.Net.TestProgram", "src\TestProgram\Starscript.Net.TestProgram.csproj", "{3046ED02-73C4-49D7-A697-4995642D2921}"
88
EndProject
9+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{36F870C1-3E5F-485F-B426-F0645AF78751}"
10+
ProjectSection(SolutionItems) = preProject
11+
README.md = README.md
12+
.github\workflows\main.yml = .github\workflows\main.yml
13+
EndProjectSection
14+
EndProject
15+
916
Global
1017
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1118
Debug|Any CPU = Debug|Any CPU

0 commit comments

Comments
 (0)