Home Development of Websites ObjectScript as a new language for web development

ObjectScript as a new language for web development

by admin

ObjectScript is a new embedded object-oriented programming language with open source ObjectScript extends the capabilities of languages such as JavaScript, Lua, Ruby, Python, and PHP.You can read about the syntax of the language at this article
Recently the performance of the virtual machine has been significantly improved, the kernel and the specification have been stabilized, support for exceptions (try, catch, throw) has been added to the language, and a release of the OS 1.0 OS 1.0, documentation and an open web site are being prepared.

First OS web page

Let’s create a document index.osh in the rootof our site:

<!doctype html> <html> <head> <title> OS-FCGI FastCGI demo</title> </head> <body> <h1> Hello world!</h1> <h2> ObjectScript FastCGI demo</h2> <p> <%echo "Welcome! <br /> "var num = 20var r = {|a| a <= 1 ? 1 : a*_F(a-1)}(num)printf("factorial of %v = %v", num, r)%> </p> </body> </html>

ObjectScript as a new language for web development

For the purposes of web development, the following features have been added to the language parser :
Automatic detection UTF-8 BOM – are three invisible service bytes (EF BB BF) at the beginning of a UTF-8 encoded document.If BOM is present it will not be sent in the output stream (the problem with sending BOM is encountered e.g.in PHP scripts which block sending HTTP headers).
2. Tags added <%... %> and <%=... %>
3. OS works with its two file extensions : os and osh
When using the extension os , the parser activates the ObjectScript recognition mode at the beginning of the file, i.e. it is a normal OS script.
When using osh (designed specifically for web development), the file starts with the output content (i.e., what is sent to output). To switch to scripting mode, you need to use the tag <% or <%= To switch back to output content mode, you must use the tag %>
Tag <%= outputs the value following it, e.g, <%=value%> or <%=sprintf("%.2f", num)%>
You can also use html and htm extensions which are handled similarly to osh. This can be useful when using html editors with syntax highlighting. For OS syntax highlighting, the JavaScript syntax highlighting rules work best.

ObjectScript connectivity technology for the web

There are many ways to connect scripting languages to the web, such as: web server, apache module, phusion passenger, fastcgi, etc. Each way has its own advantages and disadvantages.
For high load sites using e.g. PHP, nginx + php-fpm (fastcgi) are well known. Nginx itself is a good product and well-proven itself, it gives statics (images, css, etc.), and the scripts are redirected to the php-fpm protocol fastcgi. This solution provides high stability and fast processing of requests. In addition, fastcgi, you can connect to apache and other web servers.
As an implementation of the fastcgiprotocol in C++, the cross-platform library was chosen fastcgi , with which the OS-FCGI was developed.
OS-FCGI is a FastCGI service for developing websites using ObjectScript.

Installing OS-FCGI under linux from sources

1. Clone the repository https://github.com/unitpoint/os-fcgi%20

git clone https://github.com/unitpoint/os-fcgi.git

2. execute from under root the following commands :

cd ./os-fcgi/mkdir build cd buildcmake -DCMAKE_INSTALL_PREFIX=/ ..makemake installservice os-fcgi restart

The os-fcgi service will run in 8-stream mode and listen on port 9000 to process fastcgi requests.

How to connect OS-FCGI to NGINX and APACHE

An example of a basic configuration file to connect an OS-FCGI service to NGINX:

server {listen 80;server_name mydomain.com www.mydomain.com;root /home/myuser/mydomain.com/www;error_log /var/log/nginx/error.mydomain.com.log;access_log off;location ~ /.ht {deny all;}location ~ /.git {deny all;}location / {try_files $uri $uri/ /index.osh /index.os;}location ~* .(jpg|jpeg|png|gif|swf|flv|mp4|mov|avi|wmv|m4v|mkv|ico|js|css|txt)$ {access_log off;expires 7d;}charset utf-8;location ~ ^.+.osh? {fastcgi_split_path_info ^(.+.osh?)(.*)$;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.osh;include fastcgi_params;fastcgi_intercept_errors on;fastcgi_ignore_client_abort on;fastcgi_read_timeout 360;}}

An example of a basic configuration file for connecting the OS-FCGI service to APACHE:

<VirtualHost mydomain.com:80> ServerAdmin webmaster@mydomain.comDocumentRoot "/home/myuser/mydomain.com/www"ServerName mydomain.comFastCgiExternalServer "/home/myuser/mydomain.com/www" -host 127.0.0.1:9000<Directory "/home/myuser/mydomain.com/www"> # SetHandler fastcgi-scriptAddHandler fastcgi-script .oshAddHandler fastcgi-script .osOptions Indexes FollowSymLinks MultiViews ExecCGIAllowOverride allOrder Deny, AllowDeny from allAllow from 127.0.0.1</Directory> </VirtualHost>

Testing OS-FCGI on Windows

In order to try out web programming on OS on Windows, you must :
1. Clone the OS-FCGI project repository at github.com/unitpoint/os-fcgi
2. open Visual Studio solution os-fcgiwin32os-fcgi.sln
3. choose win32 or x64 configuration, compile and run the os-fcgi project
4. configure the web server to handle requests via fastcgi
After starting os-fcgi, it will be fully capable of handling fastcgi requests on port 9000 in single-threaded mode. Note: Under Linux platforms, os-fcgi is implemented as a service and runs in 8-stream mode.

Using OS-FCGI under Denver

To quickly run a web application on OS on Windows, you can use the software package Denver
Create a configuration file c:{WebServersusrlocalapacheconfextrahttpd-osfcgi.conf with the following content :

<VirtualHost osfcgi:80> ServerAdmin webmaster@osfcgiDocumentRoot "c:/Sources/objectscript.org/www"ServerName osfcgiFastCgiExternalServer "c:/Sources/objectscript.org/www" -host 127.0.0.1:9000<Directory "c:/Sources/objectscript.org/www"> # SetHandler fastcgi-scriptAddHandler fastcgi-script .oshOptions Indexes FollowSymLinks MultiViews ExecCGIAllowOverride allOrder Deny, AllowDeny from allAllow from 127.0.0.1</Directory> </VirtualHost>

Note : c:WebServers is the default path during Denver installation, you should change it to your path if needed, instead of c:/Sources/objectscript.org/www you should correctly spell out the path to the test site.
Edit c:{WebServersusrlocalapacheconfhttpd.conf, you must find the phrase : If you want to create the virtual host manually and add the connection httpd-osfcgi.conf. An example of the httpd.conf part with the changes made :

# If you manually want to create a virtual host with specific# settings, then do it right after this comment.Include conf/extra/httpd-osfcgi.conf

Now you can restart Denver and open the address in your browser osfcgi (just don’t forget to add the index.osh file described earlier to the site folder).
You can also download the complete website repository objectscript.org (there’s test content there now, the site is running on OS) at https://github.com/unitpoint/objectscript.org With examples, such as, core.os – startup script for web application, buffered output, automatic loading of classes when first used in code, etc.
Comments, feedback, suggestions are welcome. Good luck!
Thank you : To Igor Bogomolov for developing the cmake configuration and setting up the os-fcgi service for linux.
Other relevant articles about ObjectScript:

You may also like