adjust docs
This commit is contained in:
parent
e519d2d80b
commit
94c0831533
@ -14,7 +14,8 @@ class Logger
|
|||||||
setLogger(Logger())
|
setLogger(Logger())
|
||||||
|
|
||||||
// Using an anonymous class
|
// Using an anonymous class
|
||||||
setLogger(class {
|
setLogger(class
|
||||||
|
{
|
||||||
pub fun log(String msg)
|
pub fun log(String msg)
|
||||||
{
|
{
|
||||||
print(msg)
|
print(msg)
|
||||||
@ -23,7 +24,8 @@ setLogger(class {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
setLogger(class(Int param1) -> SomeClass(param1), SomeInterface {
|
setLogger(class(Int param1) -> SomeClass(param1), SomeInterface
|
||||||
|
{
|
||||||
pub fun method()
|
pub fun method()
|
||||||
{
|
{
|
||||||
// code
|
// code
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
Basically kotlin syntax.
|
Basically kotlin syntax.
|
||||||
|
|
||||||
Methods have to have a first parameter `$`.
|
|
||||||
|
|
||||||
|
|
||||||
## Create a new instance of a class
|
## Create a new instance of a class
|
||||||
|
|
||||||
@ -29,19 +27,19 @@ val instance = SimpleClass()
|
|||||||
class SimpleClass
|
class SimpleClass
|
||||||
{
|
{
|
||||||
// Properties are private by default
|
// Properties are private by default
|
||||||
var String? name;
|
var String? name = ...
|
||||||
|
|
||||||
// Made public with `pub`
|
// Made public with `pub`
|
||||||
pub var String? surname;
|
pub var String? surname = ...
|
||||||
|
|
||||||
// Methods are private by default
|
// Methods are private by default
|
||||||
fun display_name($)
|
fun display_name()
|
||||||
{
|
{
|
||||||
// `$` is used instead of $this
|
// `$` is used instead of $this
|
||||||
print($name)
|
print($name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fun get_name($) -> String?
|
pub fun get_name() -> String?
|
||||||
{
|
{
|
||||||
$name
|
$name
|
||||||
}
|
}
|
||||||
@ -61,7 +59,7 @@ Kotlin style
|
|||||||
```thp
|
```thp
|
||||||
class Cat(val String name)
|
class Cat(val String name)
|
||||||
{
|
{
|
||||||
pub fun get_name($) -> String
|
pub fun get_name() -> String
|
||||||
{
|
{
|
||||||
$name
|
$name
|
||||||
}
|
}
|
||||||
@ -71,6 +69,21 @@ val michifu = Cat("Michifu")
|
|||||||
print(michifu.get_name())
|
print(michifu.get_name())
|
||||||
```
|
```
|
||||||
|
|
||||||
|
With kotlin's `init` block.
|
||||||
|
|
||||||
|
```thp
|
||||||
|
class Dog(val String name)
|
||||||
|
{
|
||||||
|
val Int name_length
|
||||||
|
|
||||||
|
init
|
||||||
|
{
|
||||||
|
print("Dog has been instantiated")
|
||||||
|
$name_length = name.length()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Inheritance
|
## Inheritance
|
||||||
|
|
||||||
Kotlin style
|
Kotlin style
|
||||||
@ -78,7 +91,7 @@ Kotlin style
|
|||||||
```thp
|
```thp
|
||||||
class Animal(val String name)
|
class Animal(val String name)
|
||||||
{
|
{
|
||||||
pub fun say_name($)
|
pub fun say_name()
|
||||||
{
|
{
|
||||||
print($name)
|
print($name)
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
interface Serializable
|
interface Serializable
|
||||||
{
|
{
|
||||||
// Methods are always public in interfaces
|
// Methods are always public in interfaces
|
||||||
fun serialize($) -> String
|
fun serialize() -> String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Cat -> Serializable
|
class Cat -> Serializable
|
||||||
{
|
{
|
||||||
pub fun Serializable($) -> String
|
pub fun Serializable() -> String
|
||||||
{
|
{
|
||||||
// code
|
// code
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"generate": "md-docs",
|
"generate": "md-docs",
|
||||||
"watch": "concurrently -k \"pnpm tailwind:watch\" \"serve ./static/ -l 3333\"",
|
"dev": "concurrently -k \"pnpm tailwind:watch\" \"serve ./static/ -l 3333\"",
|
||||||
"tailwind:watch": "tailwindcss -i ./tailwind.css -o ./static/css/out.css --watch",
|
"tailwind:watch": "tailwindcss -i ./tailwind.css -o ./static/css/out.css --watch",
|
||||||
"tailwind:build": "tailwindcss -i ./tailwind.css -o ./static/css/out.css --minify"
|
"tailwind:build": "tailwindcss -i ./tailwind.css -o ./static/css/out.css --minify"
|
||||||
},
|
},
|
||||||
|
@ -15,7 +15,7 @@ Prism.languages.thp = {
|
|||||||
pattern: /(["])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
pattern: /(["])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
||||||
greedy: true,
|
greedy: true,
|
||||||
},
|
},
|
||||||
"keyword": /\b(?:static|const|enum|loop|use|break|catch|continue|do|else|finally|for|fun|if|in|fn|nil|return|throw|try|while|val|var|type|match|with|of|abstract|class|interface|private|pub|obj|override|open)\b/,
|
"keyword": /\b(?:static|const|enum|loop|use|break|catch|continue|do|else|finally|for|fun|if|in|fn|nil|return|throw|try|while|val|var|type|match|with|of|abstract|class|interface|private|pub|obj|override|open|init)\b/,
|
||||||
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
||||||
"operator": /[<>]=?|[!=]=?=?|--?|\$|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
"operator": /[<>]=?|[!=]=?=?|--?|\$|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
||||||
"punctuation": /[{}[\];(),.]/,
|
"punctuation": /[{}[\];(),.]/,
|
||||||
|
Loading…
Reference in New Issue
Block a user