[Klone-users] recommended source code reading order

thomas fossati tho at koanlogic.com
Tue Dec 1 12:24:25 EST 2009


Hi Patrick,

On Dec 1, 2009, at 2:04 PM, Patrick wrote:
> I have two goals in mind. One I would like to design a device that  
> would translate URL arguments directly into GPIB commands. GPIB is a  
> common bus used in Lab and test and measurement applications. This  
> way an end user could control their GPIB instruments directly from  
> an pure HTML page.

I'd suggest you to try out the kilt supplier, an url-regex dispatcher  
which seems quite suitable for the specific task.  If you are  
interested you can peek at this example application:
     http://www.koanlogic.com/download/klone/klapp-kilt-1.0.0.tar.gz

Other sample klapps (not kilt related) that interface the hardware are:
     http://www.koanlogic.com/download/klone/pxa-regs-2.1.0.tar.gz
     http://www.koanlogic.com/download/klone/fox-demo-2.1.0.tar.gz
     http://www.koanlogic.com/download/klone/fox-vhdl-2.1.0.tar.gz

enjoy :)

> And....I guess I am lazy. I would like to stick to one stack as much  
> as I can . I would like to use Klone and Lua for my own site too.
>
> So I guess with the embedded device I am looking at option 2, pre- 
> compiled but the web site would likely be option 1 with Lua code run  
> dynamically at run time.

Klone has a CGI interface which must be explicitly enabled via -- 
enable_sup_cgi configure argument.  Suppose that your hello.lua file  
is stored in the /dir/to/my/cgi-bin/ directory and that it is going to  
be interpreted through /usr/local/bin/lua, i.e. something like (poetic  
licence):

$ cat /dir/to/my/cgi-bin/hello.lua
#!/usr/local/bin/lua
print("HTTP/1.1 200 OK\n")
print("Content-Type: text/html;\n")
print("<html>hello!</html>")


then your kloned.conf looks like:

{
     ...

     cgi
     {
         # script_alias (i.e. the dir where scripts are allowed)
         script_alias    /cgi-bin   /dir/to/my/cgi-bin/

         # run .lua files as-is (must produce a valid HTTP reponse)
         lua.handler     exec
     }
}

and the resource is made available through http://your-web-server/cgi- 
bin/hello.lua

That said, the plain CGI interface sucks (see http://koanlogic.com/klone/bench/intel-xeon-gnu-linux/php.html 
  to compare KLone CGIs against less brutal exec interfaces), and the  
performance penalty can be huge, all the more when compared to the  
native .kl1 page ... perhaps it's time for us to begin working on a  
FastCGI interface :)

ciao, t.

PS: Indeed C is a beautiful and clean language, don't be scared  
working with it, and inside .kl1 pages use the LibU features which  
come for free :)




More information about the klone-users mailing list