Skip to content

Commit

Permalink
Merge pull request #106 from lf-lang/release-0.7.0
Browse files Browse the repository at this point in the history
Release 0.7.0
  • Loading branch information
lhstrh authored May 1, 2024
2 parents 59df69b + daa8000 commit 3155c13
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 142 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
needs: find-latest-release
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Java 17
run: |
echo "$JAVA_HOME_17_X64/bin" >> $GITHUB_PATH
Expand All @@ -38,7 +38,7 @@ jobs:
runs-on: ubuntu-latest
needs: find-latest-release
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Java 17
run: |
echo "$JAVA_HOME_17_X64/bin" >> $GITHUB_PATH
Expand Down
38 changes: 25 additions & 13 deletions examples/C/src/ReflexGame/ReflexGame.lf
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ reactor RandomSource(min_time: time = 2 sec, max_time: time = 8 sec) {
=}
}

/**
* Upon receiving a prompt, record the time of the prompt, then listen for user input. When the user
* hits return, then schedule a physical action that records the time of this event and then report
* the response time.
*/
reactor GetUserInput {
/** Listen for keyboard input and produce it on the output when it arrives. */
reactor User {
output out: char
physical action user_response: char

preamble {=
// Thread to read input characters until an EOF is received.
// Each time a newline is received, schedule a user_response action.
Expand All @@ -82,20 +81,31 @@ reactor GetUserInput {
}
=}

physical action user_response: char
reaction(startup) -> user_response {=
// Start the thread that listens for Enter or Return.
lf_thread_t thread_id;
lf_thread_create(&thread_id, &read_input, user_response);
=}

reaction(user_response) -> out {=
lf_set(out, user_response->value);
=}
}

/**
* Upon receiving a prompt, record the time of the prompt. When user input arrives, schedule a
* physical action that records the time of this event and then report the response time. Also,
* check for cheating.
*/
reactor GetUserInput {
state prompt_time: time = 0
state total_time_in_ms: int = 0
state count: int = 0

input prompt: int
input user_response: char
output another: int

reaction(startup) -> user_response {=
// Start the thread that listens for Enter or Return.
lf_thread_t thread_id;
lf_thread_create(&thread_id, &read_input, user_response);
=}

reaction(prompt) {=
self->prompt_time = lf_time_logical();
=}
Expand Down Expand Up @@ -134,6 +144,8 @@ reactor GetUserInput {
main reactor ReflexGame {
p = new RandomSource()
g = new GetUserInput()
u = new User()
p.out -> g.prompt
g.another -> p.another
u.out -> g.user_response
}
18 changes: 9 additions & 9 deletions examples/C/src/browser-ui/WebSocket.lf
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
/**
* Demo of a use of WebSocketServer enabling a user interface realized in the browser. Compile and
* run this program, then open WebSocket.html in your favorite browser. This example program sends
* to the web page a counting sequence. It also accepts text messages from the web page and prints
* them on standard output.
* to all connected web pages a counting sequence. The count starts when the first web page
* connects. This also accepts text messages from the web page and prints them on standard output.
*
* This example also shows how to limit the number of connections to just two. If you try to open
* the WebSocket.html web page more than twice, only the first two attempts will succeed in
* connecting. By default, WebSocketServer imposes no such limit.
*
* In this example, if you connect two clients, one will receive even numbered counts, and the other
* will receive odd numbered counts. This is because the count state variable is shared across all
* clients.
*
* This uses the <a href="https://libwebsockets.org">libwebsockets</a> (see <a
* href="https://libwebsockets.org/lws-api-doc-main/html/index.html">API documentation</a> and <a
* href="https://libwebsockets.org/lws-api-doc-main/html/md_READMEs_README_build.html">installation
Expand All @@ -31,6 +27,7 @@ import WebSocketServer from "../lib/WebSocketServer.lf"

main reactor {
state count: int = 0
state running: bool = false
logical action send_action: web_socket_instance_t*

s = new WebSocketServer(
Expand All @@ -49,7 +46,7 @@ main reactor {
web_socket_message_t* container = (web_socket_message_t*)malloc(sizeof(web_socket_message_t));
container->message = message;
container->length = strlen(message) + 1;
container->wsi = send_action->value->wsi;
container->wsi = NULL; // Broadcast to all connected clients.
container->binary = false; // Sending text.

lf_set(s.send, container);
Expand All @@ -61,8 +58,11 @@ main reactor {
if (s.connected->value.connected) {
lf_print("======== Connected a new client");

// Start sending.
lf_schedule_copy(send_action, 0, &s.connected->value, 1);
// Start sending if not already started.
if (!self->running) {
lf_schedule_copy(send_action, 0, &s.connected->value, 1);
self->running = true;
}
} else {
lf_print("======== Disconnected client");
}
Expand Down
Loading

0 comments on commit 3155c13

Please sign in to comment.