|
44 | 44 |
|
45 | 45 | <section class="desc markdown"> |
46 | 46 | <h1 id="ochescript">OcheScript</h1> |
47 | | -<p><strong>Oche <em>(pronounced "ock-ee")</em>. The official name for the throwing line in a game of darts.</strong></p> |
48 | | -<p>Embedded script language for Flutter/Dart applications.</p> |
49 | 47 | <p><a href="https://github.com/atebitftw/ochescript/actions/workflows/dart.yaml"><img src="https://github.com/atebitftw/ochescript/actions/workflows/dart.yaml/badge.svg" alt="Dart CI"></a></p> |
50 | | -<p><img src="https://atebitftw.github.io/site/assets/oche_script_logo_640.png" alt="OcheScript Logo"></p> |
| 48 | +<p><img src="https://atebitftw.github.io/site/assets/oche_script_logo_640.png" alt="OcheScript Logo"> |
| 49 | +<em>Oche <em>(pronounced "ock-ee")</em>. The official name for the throwing line in a game of darts.</em></p> |
| 50 | +<h4 id="embedded-script-language-for-flutterdart-applications">Embedded script language for Flutter/Dart applications.</h4> |
51 | 51 | <h2 id="key-features">Key Features</h2> |
52 | | -<p>OcheScript is a lightweight, dynamically typed, object-oriented, scripting language designed for embedding into Dart applications.</p> |
| 52 | +<p>OcheScript is an extensible, lightweight yet powerful scripting language designed for embedding into Dart/Flutter applications.</p> |
53 | 53 | <ul> |
54 | | -<li>Convenient Dart interop capabilities.</li> |
55 | | -<li>Extensible via native methods and functions.</li> |
56 | | -<li>Object-oriented programming features (classes, methods, properties, etc.).</li> |
57 | | -<li>Closures and lambdas.</li> |
58 | | -<li>(Limited) Asynchronous support (async/await).</li> |
59 | | -<li>String interpolation.</li> |
60 | | -<li>Try/catch exception handling.</li> |
61 | | -<li>Lightweight preprocessor directive capabilities.</li> |
62 | | -<li><code>.oche</code> script file syntax highlighting extension for VSCode/Antigravity.</li> |
| 54 | +<li><strong>Convenient <a href="https://github.com/atebitftw/ochescript/blob/main/doc/dart_interop.md">Dart interop</a> Features.</strong> |
| 55 | +<ul> |
| 56 | +<li><strong>Initialize OcheScript globals from Dart.</strong></li> |
| 57 | +<li><strong>Call Dart functions from OcheScript and get return values.</strong></li> |
| 58 | +<li><strong>Send values from OcheScript to Dart at any time.</strong></li> |
| 59 | +</ul> |
| 60 | +</li> |
| 61 | +<li><strong>Extensible - Make It Your Own</strong> |
| 62 | +<ul> |
| 63 | +<li><strong>Define <a href="https://github.com/atebitftw/ochescript/blob/main/doc/native_methods.md">extension methods</a> bound to supported types (many already included).</strong></li> |
| 64 | +<li><strong>Define <a href="https://github.com/atebitftw/ochescript/blob/main/doc/native_functions.md">global functions</a> that can execute arbitrary Dart code (many already included).</strong></li> |
| 65 | +</ul> |
| 66 | +</li> |
| 67 | +<li><strong>Object-Oriented Programming Features (classes, methods, properties, etc.).</strong></li> |
| 68 | +<li><strong>Closures and Lambdas.</strong></li> |
| 69 | +<li><strong>String Interpolation.</strong></li> |
| 70 | +<li><strong>Try/Catch Exception Handling.</strong></li> |
| 71 | +<li><strong>Asynchronous Support (async/await).</strong></li> |
| 72 | +<li><strong>Lightweight Preprocessor Directive Capabilities.</strong></li> |
| 73 | +<li><strong><code>.oche</code> Script File Syntax Highlighting Extension for VSCode/Antigravity.</strong></li> |
| 74 | +<li><strong>Comprehensive API and Language Documentation.</strong></li> |
63 | 75 | </ul> |
64 | 76 | <h2 id="hello-world-in-ochescript">Hello World In OcheScript</h2> |
65 | | -<p><em>In a text file with extension <code>.oche</code></em></p> |
66 | | -<pre class="language-js"><code class="language-js">print("Hello World!"); |
67 | | -</code></pre> |
68 | | -<p>Running from Dart:</p> |
69 | 77 | <pre class="language-dart"><code class="language-dart">import 'package:oche_script/oche_script.dart' as oche; |
70 | 78 |
|
71 | 79 | Future<void> main() async { |
72 | 80 | final result = await oche.compileAndRun(r"print("Hello World!");"); |
73 | 81 | } |
| 82 | + |
| 83 | +// Hello World! |
74 | 84 | </code></pre> |
75 | 85 | <h2 id="getting-started">Getting Started</h2> |
76 | 86 | <p>See the <a href="https://github.com/atebitftw/ochescript/blob/main/doc/getting_started.md">Getting Started</a> document for more information.</p> |
77 | 87 | <h2 id="language-specification">Language Specification</h2> |
78 | 88 | <p>See the <a href="https://github.com/atebitftw/ochescript/blob/main/doc/language_specification.md">Language Specification</a> document for more information.</p> |
79 | 89 | <h2 id="library-api">Library API</h2> |
80 | | -<p>See the <a href="https://github.com/atebitftw/ochescript/tree/main/doc/api">API</a> document for more information. This is an HTML document generated from the Dartdoc comments in the source code.</p> |
| 90 | +<p>See the <a href="https://pub.dev/documentation/oche_script/latest/">API</a> document for more information. This is an HTML document generated from the Dartdoc comments in the source code.</p> |
81 | 91 | <h2 id="dart-interop">Dart Interop</h2> |
82 | 92 | <p>See the <a href="https://github.com/atebitftw/ochescript/blob/main/doc/dart_interop.md">Dart Interop</a> document for more information.</p> |
83 | 93 | <h2 id="why-does-this-exist">Why Does This Exist?</h2> |
84 | 94 | <p>I work on some very large-scale Flutter projects that sometimes require a bit of dynamic runtime automation, and I found that I needed execute arbitrary code at runtime in certain situations. I built OcheScript to meet this need. In the Flutter/Dart ecosystem, there are probably five people that need this kind of thing, and I am one of them. To the other four, I say: "Hello World!".</p> |
85 | 95 | <p><em>Side Note: Dart technically does have arbitrary code execution capability via <code>dart:mirrors</code>, but I personally do not consider it to be a viable approach for many production application scenarios, especially anything Flutter-based (mirrors disallowed). Another reason to avoid mirrors: As soon as you bring in mirrors, you lose tree-shaking.</em></p> |
86 | | -<h2 id="error-handling">Error Handling</h2> |
87 | | -<p>Unless captured in a <code>try/catch</code> block, runtime errors cause script execution to halt with an error message.</p> |
88 | | -<p>Errors are not emitted to stdout by default. They are usually reported via the <a href="https://pub.dev/packages/logging">Logging Package</a> at level WARNING and above. To listen to these errors, you can use the <code>Logging</code> class from the <code>logging</code> package.</p> |
89 | | -<pre class="language-dart"><code class="language-dart">// (assumes you've added the logging package as a dependency in your pubspec.yaml) |
90 | | -import 'package:logging/logging.dart'; |
91 | | -import 'package:oche_script/oche_script.dart' as oche; |
92 | | - |
93 | | -Future<void> main() async { |
94 | | - Logger.root.level = Level.WARNING; |
95 | | - Logger.root.onRecord.listen((record) { |
96 | | - print("${record.level.name}: ${record.message}"); |
97 | | - // emits the error message and stack trace |
98 | | - }); |
99 | | - |
100 | | - final result = await oche.compileAndRun(r"print("Hello World!");"); |
101 | | - |
102 | | - print("Return Code: ${result['return_code']}"); |
103 | | - if (result.containsKey('error')) { |
104 | | - print("Error: ${result['error']}"); |
105 | | - } |
106 | | -} |
107 | | -</code></pre> |
108 | | -<p>Error messages are also placed in the return map of the <code>compileAndRun</code> function (without stack trace). The map has the following structure:</p> |
109 | | -<pre class="language-dart"><code class="language-dart">{ |
110 | | - "error": "{error message}", |
111 | | - "return_code": 1, |
112 | | - // other stuff emitted by any out() functions in the script. |
113 | | -} |
114 | | -</code></pre> |
115 | | -<h3 id="why-not-just-print-errors-to-stdout">Why not just print errors to stdout?</h3> |
116 | | -<p>Since OcheScript is primarily designed for use as an embedded language in other Dart/Flutter applications, stdout is not reliably available on various platforms. Using the logging package gives the developer more flexibility in how and where they receive error messages.</p> |
117 | | -<p>If you want the error message to be printed to stdout, you can use the <code>Logging</code> class from the <code>logging</code> package to listen to the <code>Logger</code> at level WARNING and above.</p> |
118 | | -<h3 id="included-library-error-reporting">Included Library Error Reporting</h3> |
119 | | -<p>When using the <code>#include</code> directive to include other "library" files into your script, OcheScript tracks the original source file and line number. If a runtime error occurs within an included file, the error message will be prefixed with the file name and line number, like so:</p> |
120 | | -<pre class="language-dart"><code>Runtime error: [my_lib:42] Undefined variable 'foo'. |
121 | | -</code></pre> |
122 | | -<p>This is useful for debugging scripts that are composed of multiple files.</p> |
123 | 96 | <h2 id="these-batteries-are-not-included">These Batteries Are Not Included</h2> |
124 | 97 | <ul> |
125 | 98 | <li>No module system (beyond <code>#INCLUDE</code> directive)</li> |
@@ -258,7 +231,7 @@ <h5 class="hidden-xs"><span class="package-name">oche_script</span> <span class= |
258 | 231 | <footer> |
259 | 232 | <span class="no-break"> |
260 | 233 | oche_script |
261 | | - 1.1.0 |
| 234 | + 1.1.1 |
262 | 235 | </span> |
263 | 236 |
|
264 | 237 | </footer> |
|
0 commit comments