-
-
Notifications
You must be signed in to change notification settings - Fork 272
Feat/add zig wasm #853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/add zig wasm #853
Changes from all commits
45b8cc1
c4f5cd1
dbfc085
f7c306e
5a3ed1a
9a42cb9
6ed31d4
c4930dc
b843877
47dd3c5
e8a99c6
959dee2
5214081
5e6b955
2b92dad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # Zig (Wasm) | ||
|
|
||
| Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software. | ||
|
|
||
| In LiveCodes, Zig runs in the browser using WebAssembly with a WASI-compatible runtime environment. | ||
|
|
||
| ## Usage | ||
|
|
||
| Demo: | ||
|
|
||
| import LiveCodes from '../../src/components/LiveCodes.tsx'; | ||
| export const zigConfig = { | ||
| activeEditor: 'script', | ||
| script: { | ||
| language: 'zig-wasm', | ||
| content: `const std = @import("std");\n | ||
| pub fn main() !void { | ||
| const stdout = std.io.getStdOut().writer();\n | ||
| const sorted_array = [_]i32{ 1, 3, 5, 7, 9, 11, 13, 15 }; | ||
| const item_to_search: i32 = 7;\n | ||
| const result = binarySearch(i32, &sorted_array, item_to_search);\n | ||
| if (result == -1) { | ||
| try stdout.print("Result: Item not found in the array.\\n", .{}); | ||
| } else { | ||
| try stdout.print("Result: Item found at index -> {}\\n", .{result}); | ||
| } | ||
| }\n | ||
| fn binarySearch(comptime T: type, arr: []const T, item: T) i32 { | ||
| var left: usize = 0; | ||
| var right: usize = arr.len;\n | ||
| while (left < right) { | ||
| const mid = left + (right - left) / 2;\n | ||
| if (arr[mid] == item) { | ||
| return @intCast(mid); | ||
| }\n | ||
| if (arr[mid] > item) { | ||
| right = mid; | ||
| } else { | ||
| left = mid + 1; | ||
| } | ||
| }\n | ||
| return -1; | ||
| }`, | ||
| }, | ||
| mode: 'simple', | ||
| editor: 'auto', | ||
| tools: { | ||
| status: 'full', | ||
| }, | ||
| }; | ||
|
|
||
| <LiveCodes config={zigConfig}></LiveCodes> | ||
|
|
||
| ### Communication with JavaScript | ||
|
|
||
| The Zig code runs in the context of the result page. A few helper properties and methods are available in the browser global `livecodes.zig` object: | ||
|
|
||
| - `livecodes.zig.input`: The initial standard input passed to the Zig code. | ||
| - `livecodes.zig.loaded`: A promise that resolves when the Zig environment (WebAssembly runtime) is fully loaded (and rejects if it fails to load). Other helpers should be used after this promise resolves. | ||
| - `livecodes.zig.output`: The standard output from the Zig code execution. | ||
| - `livecodes.zig.run`: A function that runs the Zig code with new input. This function takes a string as input and returns a promise that resolves with an object containing the `output`, `error`, and `exitCode` properties. | ||
|
|
||
| Example: | ||
|
|
||
| <LiveCodes template="zig-wasm" params={{ activeEditor: 'markup' }} height="80vh"></LiveCodes> | ||
|
|
||
| ## Language Info | ||
|
|
||
| ### Name | ||
|
|
||
| `zig-wasm` | ||
|
|
||
| ### Aliases / Extensions | ||
|
|
||
| `zig`, `zig-wasm` | ||
|
|
||
| ### Editor | ||
|
|
||
| `script` | ||
|
|
||
| ## Compiler | ||
|
|
||
| Zig compiler in WebAssembly. | ||
|
|
||
| ### Version | ||
|
|
||
| Zig 0.14.0 | ||
|
|
||
| ## Code Formatting | ||
|
|
||
| Code formatting is not currently available for Zig. | ||
|
|
||
| ## Live Reload | ||
|
|
||
| By default, new code changes are sent to the result page for re-evaluation without a full page reload, avoiding the need to reinitialize the Zig WebAssembly environment. This behavior can be disabled by adding the code comment `// __livecodes_reload__` to the Zig code, which forces a full page reload. | ||
|
|
||
| This comment can be added in the `hiddenContent` property of the editor for embedded playgrounds. | ||
|
|
||
| ## Starter Template | ||
|
|
||
| https://livecodes.io/?template=zig-wasm | ||
|
|
||
| ## Links | ||
|
|
||
| - [Zig](https://ziglang.org/) | ||
| - [Zig documentation](https://ziglang.org/documentation/master/index.html) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -341,6 +341,39 @@ <h3 data-i18n="language-info:csharpWasm.name">C# (Wasm)</h3> | |
| </li> | ||
| </ul> | ||
| </section> | ||
|
|
||
| <section data-lang="zig-wasm"> | ||
| <h3 data-i18n="language-info:zigWasm.name">Zig (Wasm)</h3> | ||
| <div data-i18n="language-info:zigWasm.desc" data-i18n-prop="innerHTML"> | ||
| Zig compiler running on WebAssembly. | ||
| </div> | ||
| <ul data-i18n="language-info:zigWasm.link" data-i18n-prop="innerHTML"> | ||
| <li> | ||
| <a href="https://ziglang.org/" target="_blank" rel="noopener">Zig website</a> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π― Functional Correctness | π‘ Minor | β‘ Quick win Export the The added As per coding guidelines, user-facing text in π€ Prompt for AI AgentsSource: Coding guidelines |
||
| </li> | ||
| <li> | ||
| <a href="https://ziglang.org/documentation/master/" target="_blank" rel="noopener" | ||
| >Zig language documentation</a | ||
| > | ||
| </li> | ||
| <li> | ||
| <a href="https://learnxinyminutes.com/docs/zig/" target="_blank" rel="noopener" | ||
| >Learn X in Y minutes, where X=Zig</a | ||
| > | ||
| </li> | ||
| <li> | ||
| <a href="{{DOCS_BASE_URL}}languages/zig-wasm" target="_blank" rel="noopener" | ||
| >LiveCodes Documentation</a | ||
| > | ||
| </li> | ||
| <li> | ||
| <a href="?template=zig-wasm" class="button" target="_parent" data-template="zig-wasm" | ||
| >Load starter template</a | ||
| > | ||
| </li> | ||
| </ul> | ||
| </section> | ||
|
|
||
| <section data-lang="diagrams"> | ||
| <h3 data-i18n="language-info:diagrams.name">Diagrams</h3> | ||
| <div data-i18n="language-info:diagrams.desc1" class="description warn">(Experimental)</div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './lang-zig-wasm'; |
Uh oh!
There was an error while loading. Please reload this page.