From 6c78271c841baf43365cc7924c0ca2da867f9e79 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 25 Feb 2022 16:57:51 +0800 Subject: update doc. --- doc/docs/doc/README.md | 98 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 15 deletions(-) (limited to 'doc') diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 98a121b..be83be3 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -81,45 +81,64 @@ export yuescript = "ζœˆδΉ‹θ„šζœ¬" * **Lua Module** -  Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module and executable with: + Install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module and executable with: ``` > luarocks install yuescript ``` -  Or you can build `yue.so` file with: + Or you can build `yue.so` file with: ``` > make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua ``` -  Then get the binary file from path **bin/shared/yue.so**. + Then get the binary file from path **bin/shared/yue.so**. * **Binary Tool** -  Clone this repo, then build and install executable with: + Clone this repo, then build and install executable with: ``` > make install ``` -  Build Yuescript tool without macro feature: + Build Yuescript tool without macro feature: ``` > make install NO_MACRO=true ``` -  Build Yuescript tool without built-in Lua binary: + Build Yuescript tool without built-in Lua binary: ``` > make install NO_LUA=true ``` ## Usage -  Require the Yuescript module in Lua: +### Lua Module + + Use Yuescript module in Lua: + +* **Case 1** +Require "your_yuescript_entry.yue" in Lua. ```Lua --- require `main.yue` in Lua -require("yue")("main") +require("yue")("your_yuescript_entry") +``` + And this code still works when you compile "your_yuescript_entry.yue" to "your_yuescript_entry.lua" in the same path. In the rest Yuescript files just use the normal **require** or **import**. The code line numbers in error messages will also be handled correctly. --- use the Yuescript compiler in Lua +* **Case 2** +Require Yuescript module and rewite message by hand. +```lua +local yue = require("yue") +local success, result = xpcall(function() + yue.require("yuescript_module_name") +end, function(err) + return yue.traceback(err) +end) +``` + +* **Case 3** +Use the Yuescript compiler function in Lua. +```lua local yue = require("yue") local codes, err, globals = yue.to_lua([[ f = -> @@ -131,7 +150,10 @@ f! lint_global = true }) ``` -  Use Yuescript tool with: + +### Yuescript Tool + + Use Yuescript tool with: ``` > yue -h Usage: yue [options|files|directories] ... @@ -160,7 +182,6 @@ Usage: yue [options|files|directories] ...   Execute raw codes: **yue -e 'print 123'**   Execute a Yuescript file: **yue -e main.yue** - ## Macro ### Common Usage @@ -226,7 +247,7 @@ if $and f1!, f2!, f3! -### Insert Raw Codes +### Insert Raw Codes A macro function can either return a Yuescript string or a config table containing Lua codes. ```moonscript @@ -324,7 +345,6 @@ import "utils" as { - ## Operator All of Lua's binary and unary operators are available. Additionally **!=** is as an alias for **~=**, and either **\\** or **::** can be used to write a chaining function call like `tb\func!` or `tb::func!`. And Yuescipt offers some other special operators to write more expressive codes. @@ -572,7 +592,6 @@ tb = - ## Module ### Import @@ -706,6 +725,54 @@ export default -> +## Try + +The syntax for Lua error handling in a common form. + +```moonscript +try + func 1, 2, 3 +catch err + print yue.traceback err + +success, result = try + func 1, 2, 3 +catch err + yue.traceback err + +try func 1, 2, 3 +catch err + print yue.traceback err + +success, result = try func 1, 2, 3 + +try + print "trying" + func 1, 2, 3 +``` + +
+try
+  func 1, 2, 3
+catch err
+  print yue.traceback err
+
+success, result = try
+  func 1, 2, 3
+catch err
+  yue.traceback err
+
+try func 1, 2, 3
+catch err
+  print yue.traceback err
+
+success, result = try func 1, 2, 3
+
+try
+  print "trying"
+  func 1, 2, 3
+
+
## Whitespace @@ -836,6 +903,7 @@ do ## Comment + ```moonscript -- I am a comment -- cgit v1.2.3-55-g6feb