Opa (programming language): Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 10:
 
Opa is a programming language for web application development release under a dual license: Gnu Affero GPL and a private license.
 
== Example source code ==
 
<source lang="c">
/**
* The type of messages sent by a client to the chatroom
*/
type message = {author: string /**The name of the author (arbitrary string)*/
; text: string /**Content entered by the user*/}
 
/**
* The chatroom.
*/
@publish room = Network.cloud("room"): Network.network(message)
 
/**
* Update the user interface in reaction to reception of a message.
*
* This function is meant to be registered with [room] as a callback.
* Its sole role is to display the new message in [#conversation].
*
* @param x The message received from the chatroom
*/
user_update(x: message) =
line = <div class="line">
<div class="user">{x.author}:</div>
<div class="message">{x.text}</div>
</div>
do Dom.transform([#conversation +<- line ])
Dom.scroll_to_bottom(#conversation)
 
/**
* Broadcast text to the [room].
*
* Read the contents of [#entry], clear these contents and send the message to [room].
*
* @param author The name of the author. Will be included in the message broadcasted.
*/
broadcast(author) =
do Network.broadcast({~author text=Dom.get_value(#entry)}, room)
Dom.clear_value(#entry)
 
/**
* Build the user interface for a client.
*
* Pick a random author name which will be used throughout the chat.
*
* @return The user interface, ready to be sent by the server to the client on connection.
*/
start() =
author = Random.string(8)
<div id=#header><div id=#logo></div></div>
<div id=#conversation onready={_ -> Network.add_callback(user_update, room)}></div>
<div id=#footer>
<input id=#entry onnewline={_ -> broadcast(author)}/>
<div class="button" onclick={_ -> broadcast(author)}>Post</div>
</div>
 
/**
* Main entry point.
*
* Construct an application called "Chat" (users will see the name in the title bar),
* embedding statically the contents of directory "resources", using the global stylesheet
* "resources/css.css" and the user interface defined in [start].
*/
server = Server.one_page_bundle("Chat",
[@static_resource_directory("resources")],
["resources/css.css"], start)
</source>
 
== External links ==
 
*[http://www.infoworld.com/d/developer-world/infoworld-review-tools-rapid-web-development-297 InfoWorld article about emerging web technologies, of which Opa]
*[httphttps://www.slideshareowasp.netorg/IamYoricindex.php/opaFile:OWASP_AppSec_Research_2010_OPA_by_Rajchenbach-owasp-2010Teller.pdf Slides of Opa presentation at OWASP 2010]
*[https://www.owasp.org/index.php/Opa OWASP Project page]
*[https://github.com/MLstate/opalang GitHub repository]