can html and c++ be linked without any external application? - html

i am working on a project which requires my c++ based code to run in a web page. taking the simplest example of "hello world" code in c++, is it possible to link this code to an html document, any help would be appreciated.
Scripting constraints: html/php/asp.net (asp.net only if this is not at all possible with html/php)

Actually, yes - provided your users are using chrome:
https://developer.chrome.com/native-client

Hacky, but working with yor constraints, is to make this "hello world" program output the whole html, and use it as a cgi. Or use php or asp to call this exec and redirect its output.
But this is not having the source code embedded in the html, like php does, but compiling the C++ to an executable and calling it from php. You can even extend php with c++.

Related

How to add R code in an HTML page

I am creating a Twitter sentimental analysis and in the html page, I am giving a tab for looking at the Word Cloud. The Word Cloud code is in R. How do I integrate the R code into my HTML page. Any idea? Thanks.
You may have to use any server side languages like php and execute your R code with php shell_exec function and return this data to html using ajax.
Either call an external R-script from php or whatever language you are using (see: this thread) , and generate the images and html-code to be included with knitr or something similar.
Or try Rstudios shiny package to serve this part of the site directly from R.

How do I call a Lua script from an HTML5 script/file/page

I want to create web pages with dynamic content. I have an HTML page, and I want to call a lua script from it
How do I invoke the lua script?
<script type="text/application" >?
<script type="text/lua" >?
Retrieve data from it? Can I do something like:
int xx = 0;
<script type=text/lua>
xx = 123;
</script>
and have any hope that xx will be 123 when the script exits?
Replace the current web page with the content generated by the lua script.
On the client-side, you can use:
Fengari, a Lua VM written in JavaScript
WebAssembly with wasm_lua
lua.js compiles Lua directly to JavaScript. Has lower compatibility but lower footprint too.
moonshine
Fengari and Moonshine execute compiled Lua bytecode. They are more compatible than lua.js, and have a lower code-size footprint than e.g. an Emscripten-compiled Lua interpreter. They may be the slowest method of all because they aren't using WASM/asm.js like the stock Lua interpreter compiled with Emscripten would, and they aren't generating JavaScript which could be subsequently JIT'ed.
I'd try using Fengari first as it seems to be most active. It has easier JS interop than something using WASM would have.
On the WWW scripts can run in two places.
In the web browser
On the web server
If you want it to run in the browser, then you need support for the language built into the browser (or provided by an extension). For all practical purposes, if you are writing webpages for the WWW, then the only language you can use in an HTML <script> is JavaScript.
If you want to run it on the web server, then you need to get your HTTPD to run the script in response to a URL being requested from it. The simplest way to achieve this is via CGI.
With CGI, the HTTPD will run a program (as a separate process) in response to the request being made. It will pass in various information about the request via STDIN and environment variables (as described in the CGI specification). The script then prints an HTTP response (header (at least a Content-Type) and body (e.g. an HTML document)) and sends it to STDOUT where the HTTPD picks it up and sends it back to the browser.
How you configure your server to run programs using CGI depends on the server. Apache has a guide for their server.
There are probably CGI libraries for Lua, but I don't know the language so cannot make any recommendations.
CGI is a slow and inefficient protocol (as it requires a new processes to be spawned for each request). There are alternatives, such as FastCGI and various language specific options. Again, I don't know what is considered optimal in Lua land.
Most of the CGI and Lua I have played with involve generating the web page and inserting the dynamic bits, rather than calling a script from a web page. So more like option C from your original question. Any HTML 4 or 5 elements you want to have could easily be added into the generated web page.
Here are some places you can check out for more detailed information:
CGILua has some good information on how to use CGI and Lua together.
This long forum page has some good examples with code and output.
The Beginning Lua Programming book has a whole chapter walking through how to set up and use CGI and Lua. (Chapter 15 - Programming for the Web)
(While some of these places are a bit dated, they still do a good job of showing how to do this sort of thing.)
Remember: If you are using cgi or fastcgi on the server side you will need the first line of your Lua file to have a pointer to wherever the Lua interpreter is, such as:
#!/usr/local/bin/lua
If you want to run Lua in browser, consider using Lua Alchemy — Lua interpreter for Flash VM.
There are also several JavaScript implementations of Lua, but they were not mature enough last time I looked.
If you want to run Lua on server, consult this answer: What web server to use for Lua web development
Lua won't run natively in the browser; JavaScript is the only scripting library
However, you can use the JavaScript library "Starlight", which implements Lua.
You can use it like this:
<!DOCTYPE html>
<html>
<body>
<!-- WARNING! This will only work if you load the starlight library later -->
<script type="application/lua">
print('Hello world')
</script>
<!-- Here we load the library for Lua -->
<script src="//cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
<script src="http://paulcuth.me.uk/starlight/browser-lib/starlight.js" data-run-script-tags></script>
</body>
</html>
If you want to run a script from a browser, consider using javascript instead.
It is very similar to Lua, and unlike Lua it's interpreted by most browsers.

Generate dynamic html

to export some data i want to be able to generate an html output.
I have some constant content to output, like html headers and footers.
My question is how to deal with that ?
Do I have to embed some template (in a resource file) and parse it to make it dynamic ?
Do I store my static content in some constant (is there a 255 char limit?) and append them while generating the dynamic content ?
Do you have some hints, useful links, or best practices to share?
Thanks
Use the Delphi TPageProducer. It generates HTML from a 'close to HTML' template which contains special tage. You respond to these tag in an event and replace them with your own data. Works a treat.
I've created a Delphi project that handles this issue also. I wanted to create a web-platform that uses Delphi-code in the same source-files as the HTML, much like other web-scripting platforms, but still compiles a library to run. (and auto-compiles on changes)
http://xxm.sf.net/
In its basic form it compiles into library that can be run by a handler for IIS (ISAPI extension), InternetExplorer (IInternetProtocol as its own URL scheme), or a stand-alone HTTP process. (Apache module and FireFix plug-in are on the way).

SCHEME: how to input html and output it as html source?

I am trying to write a simple web app in scheme and I am using Drscheme for the job. I am wondering if there is a way to input html code into a form which then outputs it in html format (into source)? Is there a library that does the job? Everytime I input something it turns out as a string, I need it to be read as html. Can someone help me? Thanks in advance!
If you want to use HTML template files, then look at the templates in the web server manual. Also, in case you're not familiar with the web server, then see the web server guide for a good introduction.

Make html validation part of build cycle

Currently when I build my site I have to manually open validate it at the 3wbc site (means when opera pops up, press ctr+alt+shft+u) for every page.
Is it possible to automatically validate every page whenever I build my pages?
P.s.: This page doesn't validate ;)
You can download and install your own copy of the validator - http://validator.w3.org/source/ - and invoke it locally instead of trekking out to w3.org for each page. Still, this requires piggybacking over a web server through plain HTTP or the API. For a simpler solution you may prefer to download the SP library - http://www.jclark.com/sp/index.htm or http://openjade.sourceforge.net/ - on which the W3 validator is based, then invoke the command 'nsgmls' from the command line.
There are of course also many desktop HTML validators that can process a batch of HTML pages at once, which may not be automated, but would certainly be much easier than manually checking each page. For example http://arealvalidator.com/ (Windows), http://www.webthing.com/software/validator-lite/install.html (Unix).
Might not be best choice for you but there's an Ant task for this: XmlValidate.
If you've got the HTML files in source control like SVN or Git, you can use a pre-commit hook script to run client-side validators on them. Or if you're feeling adventurous, you could use that method to ping another script on the server that validates the live pages...