From 540f9c41e55c0206fc3e7dca2c0a791dfa1bedf0 Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 5 Oct 2023 07:56:34 -0500 Subject: [PATCH] Fix navbar, add it to docs --- md/learn/classes/anonymous.md | 32 +++++++++++++++++++ md/learn/classes/interfaces.md | 25 +++++++++++++++ md/learn/classes/magic.md | 16 ++++++++++ md/learn/functions/declaration.md | 16 ++++++++++ md/learn/index.yaml | 6 ++++ static/index.html | 2 +- static/js/prism.thp.js | 2 +- static/template.html | 53 +++++++++++++++---------------- tailwind.config.js | 1 + tailwind.css | 6 ++-- 10 files changed, 128 insertions(+), 31 deletions(-) create mode 100644 md/learn/classes/anonymous.md create mode 100644 md/learn/classes/interfaces.md create mode 100644 md/learn/classes/magic.md diff --git a/md/learn/classes/anonymous.md b/md/learn/classes/anonymous.md new file mode 100644 index 0000000..44798ab --- /dev/null +++ b/md/learn/classes/anonymous.md @@ -0,0 +1,32 @@ +# Anonymous classes + + +```thp +class Logger +{ + pub fun log(String msg) + { + print(msg) + } +} + +// Using a class instance +setLogger(Logger()) + +// Using an anonymous class +setLogger(class { + pub fun log(String msg) + { + print(msg) + } +}) +``` + +```thp +setLogger(class(Int param1) -> SomeClass(param1), SomeInterface { + pub fun method() + { + // code + } +}) +``` diff --git a/md/learn/classes/interfaces.md b/md/learn/classes/interfaces.md new file mode 100644 index 0000000..1fca19e --- /dev/null +++ b/md/learn/classes/interfaces.md @@ -0,0 +1,25 @@ +# Interfaces + + + +```thp +interface Serializable +{ + // Methods are always public in interfaces + fun serialize($) -> String +} + + + +class Cat -> Serializable, +{ + pub fun Serializable($) -> String + { + // code + } +} + +``` + +No interface inheritance. + diff --git a/md/learn/classes/magic.md b/md/learn/classes/magic.md new file mode 100644 index 0000000..df03c7b --- /dev/null +++ b/md/learn/classes/magic.md @@ -0,0 +1,16 @@ +# Magic methods + +Are always public + +```thp + +class Cat +{ + pub fun __sleep() -> Array[String] + { + // logic + } +} + +``` + diff --git a/md/learn/functions/declaration.md b/md/learn/functions/declaration.md index fb55aa5..4a05774 100644 --- a/md/learn/functions/declaration.md +++ b/md/learn/functions/declaration.md @@ -62,6 +62,22 @@ val first = get_first_item(numbers) ``` +## Named arguments + +```thp +fun html_special_chars( + String input, + Int? flags, + String? encoding, + Bool? double_encoding, +) -> String +{ + // ... +} + +html_special_chars(input, double_encode: false) +``` + diff --git a/md/learn/index.yaml b/md/learn/index.yaml index a84823a..b94addb 100644 --- a/md/learn/index.yaml +++ b/md/learn/index.yaml @@ -60,3 +60,9 @@ children: path: definition - name: Static path: static + - name: Interfaces + path: interfaces + - name: Anonymous classes + path: anonymous + - name: Magic + path: magic diff --git a/static/index.html b/static/index.html index 9060513..a4a8fce 100644 --- a/static/index.html +++ b/static/index.html @@ -16,7 +16,7 @@ -