Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (greybel-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Greybel-JS
GreyScript transpiler/interpreter (GreyHack).
Links
- Latest changes: Changelog
- Demo Project: TEdit
- Greybel UI Demo: greybel-ui
- VSCode extension: greybel-vs
- Greyscript API: greyscript-meta
Features
- simplifying the process of importing your code into the game
- imports (supports nested import_code)
- bundler
- environment variables
- syntax sugar
- minimizing your script, depending on the size of your project you can save up to 40%
- optimizing literals (strings, booleans, numbers)
- minifying namespaces
- removing whitespaces + tabs
- obfuscate your code (even though that's just a side effect of all the steps above)
- beautify your code (can be useful to deobfuscate code)
- execute/test your code outside of GreyHack
- REPL for GreyScript
- Web UI with simplified features
Install
npm i -g greybel-js
Transpiler
Transpiler CLI
Example: greybel <myscriptfile> [output]
Arguments:
filepath File to compile
output Output directory
Options:
-V, --version Output the version number
-ev, --env-files <file...> Environment varibales files
-vr, --env-vars <vars...> Environment varibales
-en, --exclude-namespaces <vars...> Exclude namespaces from optimization
-u, --uglify Uglify your code
-b, --beautify Beautify your code
-h, --help Display help for command
-i, --installer Create installer for GreyScript (Should be used if you use import_code)
-mc, --maxChars Amount of characters allowed in one file before splitting when creating installer
-dno, --disable-namespaces-optimization Disable namespace optimization
-dlo, --disable-literals-optimization Disable literals optimization
Examples:
Most common build command:
greybel /my/code/file.src
When to use the installer flag
Use the installer flag when using import_code
.
greybel /my/code/file.src --installer
This will create an installer file which pretty much bundles all the files into one. Installer files exceeding the max char limit of Grey Hack will get splitted automatically.
Envar
Envar will put environment variables into your script. Just keep in mind to use the --env-files /path/env.conf
parameter. This might be useful if you want to use different variables for different environments. You can use multiple env files --env-file /path/default.conf --env-file /path/env.conf
.
You can also define the envars via this parameter. --env-vars random=SOME_VALUE --env-vars foo=123
//File path: env.conf
# MY COMMENT
random=SOME_VALUE
foo=123
//File path: example.src
somevar = #envar random;
foovar = #envar foo;
print(somevar) //prints "SOME_VALUE"
print(foovar) //prints "123"
Interpreter
Interpreter CLI
Example: greybel-execute <myscriptfile>
Options:
-p, --params Execution parameters
-i, --interactive Interactive parameters
For Windows you can use something like gitbash. Or just use the UI.
Local environment
Greybel GreyHack Intrinsics will automatically generate a local environment. It will also generate other computers, networks, filesystems etc on the fly. Generating is based on a seed called test
. Therefore generated entities should stay consistent.
The local computer setup is hardcoded. The admin credentials are root:test
. You will also have crypto.so
and metaxploit.so
at your local computer available.
Examples:
metax = include_lib("/lib/metaxploit.so") //returns metaxploit interface
print(metax) //prints metaxploit
myShell = get_shell("root", "test") //get local root shell
Greyscript API support
The intrinsics to support the Greyscript API are provided by Greybel Intrinsics and Greybel GreyHack Intrinsics. Keep in mind that not all of these functions are completly mocked. Also only API that is available in the stable build will be implemented.
Not yet supported:
AptClient
- only pollyfill which "returns not yet supported"Blockchain
- only pollyfill which "returns not yet supported"Wallet
- only pollyfill which "returns not yet supported"SubWallet
- only pollyfill which "returns not yet supported"Coin
- only pollyfill which "returns not yet supported"
Debugger
Pauses execution and enables you to inspect/debug your code.
index = 1
print("Hello world!")
debugger
print("Another string!")
TextMesh Pro Rich Text support
TextMesh Pro Rich Text is partially supported.
CLI
Supports
- color
- mark
- underline
- italic
- bold
- strikethrough
- lowercase
- uppercase
UI
Supports
- color
- mark
- underline
- italic
- bold
- strikethrough
- lowercase
- uppercase
- align
- cspace
- lineheight
- margin
- nobr
- pos
- size
- voffset
REPL
REPL CLI
Example: greybel-repl
For Windows you can use something like gitbash. Or just use the UI.
REPL also features a local environment and greyscript API support
Web-UI
Web UI CLI
Example: greybel-ui
This is a simple UI where you can minify code and execute code. There is also a VSCode extension. It features a lot of neat features. Like for example a debugger with breakpoints etc.
Share code
Use the share code button to generate an URL. Currently the implementation just uses the query params so watch out for any browser limitations.
It's planned in the future to implement some kind of package manager.
Syntax
Block shortcuts
while(true) if (true) then print("hello"); print("world"); return false;
Multiline lists
test = [
[
"value1",
"value3",
true
],
false,
null
]
Multiline maps
test = {
"test": {
"level2": {
"enough": true
}
},
"somelist": [
0, 1, 2
]
}
Math shortcuts
a /= b
a *= b
a -= b
a += b
a << b
a >> b
w = a >>> (b << c) >> a
a | b
a & b
a ^ b
Importing
import_code
The native import_code
is supported as well.
The implementation in this parser enables you to build files in your actual file system via an additional attribute.
// The default import_code command will just be parsed but won't actually include a file from your file system
import_code("somefile.src");
// As you can see this will adds another string behind the actual parameter. This enables the parser to build a dependency in your file system.
import_code("somefile.src":"./myProject/test.src");
This going to be very useful if you want to use the new feature but still want your script files to get optimized.
Together with the --installer
flag in the CLI it will bundle your files for you which makes it easier to copy/paste code from your file system into the game.
Nested import_code
Nested import_code
is supported now as well. Each nested import_code
will be moved to the entry file when transpiling/building.
Import
Import will use the relative path from the file it imports to.
//File path: library/hello-world.src
module.exports = function()
print("Hello world!")
end function
//File path: library/hello-name.src
module.exports = function(name)
print("Hello " + name + "!")
end function
//File path: example.src
#import HelloWord from library/hello-world;
#import HelloName from library/hello-name;
HelloWord() //prints "Hello world!"
HelloName("Joe") //prints "Hello Joe!"
Include
Include will use the relative path from the file it imports to. This will just purely put the content of a file into your script.
//File path: library/hello-world.src
hello = function()
print("Hello world!")
end function
//File path: example.src
#include library/hello-world;
hello() //prints "Hello world!"
Todo
- implement package manager
Contact
Generally you can just create an issue if you find a bug or got a feature request. Alternatively you can also contact me on discord ayecue#9086
.