ObjectScript is a new,
open source, embeddable object-oriented programming language. ObjectScript extends the capabilities of languages such as JavaScript, Lua, Ruby, Python and PHP. You can read the syntax of the language in
this article .
Recently, the performance of the virtual machine has been significantly increased, the kernel and specification has been stabilized, support for exceptions (try, catch, throw) has been added to the language, the release of
OS 1.0 has been released , documentation is being prepared and the project’s open site has been released.
The first web page on OS
Create an
index.osh document at the root of 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 " ! <br />" var num = 20 var 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 web development purposes, the following features have been added to the language parser:
1. Automatic detection of
UTF-8 BOM - these are three invisible service bytes (EF BB BF) at the beginning of the document with UTF-8 encoding. If the BOM is present, it will not be sent to the output stream (a problem with sending BOM is found, for example, in PHP scripts that block sending HTTP headers).
2. Added tags
<% ... %>
and
<%= ... %>
3. OS works with its two file extensions:
os and
osh .
When using the
os extension, the parser at the beginning of the file activates the ObjectScript script recognition mode, i.e. This is a common OS script.
When using
osh (designed specifically for web development), the file starts with output content (i.e. that is sent to output). To switch to scripting mode, you need to use the
<%
or
<%=
tag. To switch back to output mode, use the
%>
tag.
The
<%=
tag outputs the following value to output, for example,
<%=value%>
or
<%=sprintf("%.2f", num)%>
.
You can also use the html and htm extensions, which are processed similarly to osh. This can be useful when using html editors with syntax highlighting. For OS syntax highlighting, JavaScript syntax highlighting rules are best suited.
Technology connects objectScript to the web
There are many ways to connect scripting languages to the web, for example: its own web server, apache module, phusion passenger, fastcgi, etc. Each method has its pros and cons.
For sites with high load, using, for example, PHP, the nginx + php-fpm (fastcgi) bundle is well known. Nginx is a good product in itself and has proven itself well, it gives statics (pictures, css, etc.), and the execution of scripts redirects to php-fpm using the fastcgi protocol. 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 fastcgi protocol in C ++, the
fastcgi cross-platform library was chosen, using which OS-FCGI was developed.
OS-FCGI is a FastCGI protocol service for developing ObjectScript sites.
Installing OS-FCGI under linux from source
1. clone the
https://github.com/unitpoint/os-fcgi repository
git clone https:
2. run the following commands from as
root :
cd ./os-fcgi/ mkdir build && cd build cmake -DCMAKE_INSTALL_PREFIX=/ .. make make install service os-fcgi restart
The os-fcgi service will operate 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 for connecting the 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.com DocumentRoot "/home/myuser/mydomain.com/www" ServerName mydomain.com FastCgiExternalServer "/home/myuser/mydomain.com/www" -host 127.0.0.1:9000 <Directory "/home/myuser/mydomain.com/www"> # SetHandler fastcgi-script AddHandler fastcgi-script .osh AddHandler fastcgi-script .os Options Indexes FollowSymLinks MultiViews ExecCGI AllowOverride all Order Deny,Allow Deny from all Allow from 127.0.0.1 </Directory> </VirtualHost>
Testing OS-FCGI on Windows
In order to test web programming on OS under Windows, you need:
1. clone the OS-FCGI project repository at
github.com/unitpoint/os-fcgi2. open the solution os-fcgi \ win32 \ os-fcgi.sln in Visual Studio
3. choose the win32 or x64 configuration, compile and run the os-fcgi project
4. configure the web server to process requests through fastcgi
After running os-fcgi, it will be fully ready to process requests using the fastcgi protocol on port 9000 in single-threaded mode. Note: under linux, os-fcgi is implemented as a service and works in 8-stream mode.
Using OS-FCGI under Denver
To quickly launch a web application on OS under Windows, you can use the
Denver software package.
Create a configuration file c: \ WebServers \ usr \ local \ apache \ conf \ extra \ httpd-osfcgi.conf with the following content:
<VirtualHost osfcgi:80> ServerAdmin webmaster@osfcgi DocumentRoot "c:/Sources/objectscript.org/www" ServerName osfcgi FastCgiExternalServer "c:/Sources/objectscript.org/www" -host 127.0.0.1:9000 <Directory "c:/Sources/objectscript.org/www"> # SetHandler fastcgi-script AddHandler fastcgi-script .osh Options Indexes FollowSymLinks MultiViews ExecCGI AllowOverride all Order Deny,Allow Deny from all Allow from 127.0.0.1 </Directory> </VirtualHost>
Note: c: \ WebServers is the standard path when installing Denver, you need to replace it with your path if necessary, instead of c: /Sources/objectscript.org/www you need to correctly write the path to the test site.
Edit c: \ WebServers \ usr \ local \ apache \ conf \ httpd.conf, you need to find the phrase:
If you want to manually create a virtual host and add an httpd-osfcgi.conf connection. Example of the httpd.conf part with the changes made:
# # , . Include conf/extra/httpd-osfcgi.conf
Now you can restart Denver and open the
osfcgi address in your browser (just remember to add the index.osh file described earlier to the site folder).
You can also download the full repository of the
objectscript.org site (there is now test content, the site is running on the OS) via the link
https://github.com/unitpoint/objectscript.org with examples, for example,
core.os is the starting script for the web application , buffered output, automatic loading of classes when first used in code, and more. other
Comments, feedback, suggestions are welcome. Good luck!Thank you:
Igor Bogomolov for developing cmake configuration and setting up the os-fcgi service for linux.
Other relevant ObjectScript articles: