/* This function is called by Nit when using check_dictionary,
returns the dictionary at the head of the queue. */
void* NitHandleDictionary() {
- while(1) {
- struct PP_Var dictionary = DequeueDictionary();
- PnaclApp_handle_dictionary(app, &dictionary);
- }
+ struct PP_Var dictionary = DequeueDictionary();
+ PnaclApp_handle_dictionary(app, &dictionary);
+ return 0;
}
/* This function is called By Nit when waiting for a user input. */
char* NitHandleMessage() {
- while(1) {
- return DequeueMessage();
- }
+ return DequeueMessage();
}
/* Entry point */
redef fun eof do return end_reached
- # write method sends now a message to JS.
- redef fun write(s: Text)
- do
- app.post_message s.to_s
- end
+ # Redefintion of 'write' to send messages to the browser.
+ redef fun write(s: Text) do app.post_message s.to_s
redef fun is_writable: Bool do return true
# Checks if there is a dictionary in the queue, and if so the dictionary is handled automatically.
fun check_dictionary `{
- while(1) {
- NitHandleDictionary();
- }
+ NitHandleDictionary();
`}
+
+ # Infinite loop on check_dictionary
+ fun run
+ do
+ loop
+ check_dictionary
+ end
+ end
end
+
+redef interface Object
+ # Calls 'pthread_exit on current thread
+ fun exit_thread(exit_value: Int) `{
+ pthread_exit((void*) exit_value);
+ `}
+
+ # Redef of exit in order to avoid the module to crash by terminating only the Nit thread.
+ redef fun exit(exit_value: Int)
+ do
+ var dictionary = new PepperDictionary
+ dictionary["exit"] = exit_value
+ app.post_dictionary dictionary
+ exit_thread exit_value
+ end
+end
+
fun app: PnaclApp do return once new PnaclApp