Add JS sections

This commit is contained in:
Maxwell Jeffress 2024-12-13 13:14:46 +11:00
parent d09f419c0f
commit 09787d7113
3 changed files with 16 additions and 2 deletions

View File

@ -53,9 +53,10 @@ init {
} }
``` ```
**Note: Everything after this line (for now) is either experimental or in development.** Add comments to your code with `// comment here`, or `/* comment here */`
If there's any Javascript you want to run on startup, add a JS section in your init. If there's any Javascript you want to run on startup, add a JS section in your init.
``` ```
egg notepad egg notepad
@ -71,6 +72,8 @@ init {
} }
``` ```
**Note: Everything after this line (for now) is either experimental or in development.**
Variables and values/constants can be defined with `val` and `var`, just like in Kotlin. Variables and values/constants can be defined with `val` and `var`, just like in Kotlin.
``` ```
@ -89,3 +92,9 @@ init {
var myVariable = "This is a variable" var myVariable = "This is a variable"
} }
``` ```
### How to use the language
You can transpile Chookspeak to Javascript and HTML by using the program in the repository. Compile it with `gradle installDist`, then run `./build/install/chookspeak/bin/chookspeak` (add .bat if you're a crazy Windows user). You'll notice it complains about not having a file. Add the path as your argument. eg `./build/install/chookspeak/bin/chookspeak notepad.chsp`. Your program should be compiled to HTML and Javascript in valid egg format, which can be added to your Chookchat instance.
When running the transpiler, don't be worried if debug messages come up. For now, there's no way to error it other than having your egg declaration not at the start of your code.

View File

@ -1,5 +1,4 @@
// comment lmao // comment lmao
/* a confusing comment */
egg notepad egg notepad
init { init {
sendMessage "Hello there!" sendMessage "Hello there!"
@ -7,6 +6,9 @@ init {
<textarea id="dingus"> <textarea id="dingus">
} }
log "egg initialised" log "egg initialised"
js {
alert("this is an alert! i repeat - this is an alert!");
}
} }
onRecieving egg * * { onRecieving egg * * {

View File

@ -108,6 +108,9 @@ fun main(args: Array<String>) {
if (status == listOf("init", "html") && lineArgs[0] != "html") { if (status == listOf("init", "html") && lineArgs[0] != "html") {
outputHTML.appendText("${lineArgs.joinToString(" ")}\n") outputHTML.appendText("${lineArgs.joinToString(" ")}\n")
} }
if (status == listOf("init", "js") && lineArgs[0] != "js") {
outputIndexJS.appendText("${lineArgs.joinToString(" ")}\n")
}
lineCounter ++ lineCounter ++
} else if (commenting == 1) { } else if (commenting == 1) {
commenting = 0 commenting = 0