views:

149

answers:

4

I'm an intermediate C developer, trying to get better. I want to make a very basic and lightweight HTTP server with its own scripting language.

Could I use something like Lua for scripting? If not, what?

I don't want to use CGI/FastCGI like Apache does for PHP in most cases, I want my server to natively support my scripting language.

Edit: I want the scripting language to be my own, so I can decide on the syntax, etc.

+1  A: 

Why couldn't you use Lua for scripting? Its a scripting language implemented in C, replete with the necessary API.

George Jempty
I don't really know much about it, and was wondering if there were better alternatives or if Lua would be the right thing to use.
guitar-
I probably should have been more clear, I want to use my own scripting language with its own syntax, etc.
guitar-
if you're going to make your own scripting language, then I don't understand the question.
Segfault
A: 

You can use Python in the scripting side, it's easy to embed the interpreter in your server. Check this. However, you won't be able to change the syntax, but you will not have to take care of the lexing/parsing/...

If you need help embedding the Python interpreter, ask me.

Yassin
+1  A: 

What do you really want - do you want to create a new language and have a web server for it? Then write web server in that language, that proves that language qualities best :)

Or do you want to write "general purpose" web server and have a scripting language to configure its behavior (instead of "classic" configuration files)? Like Lighttpd with mod_magnet does, using Lua for this? If so, you can:

  • write that HTTP web serving stuff yourself; it's not too hard (web server capable of answering GET/POST requests is a typical school project), but there will be years of bug fighting :) if you mean it seriously, or

  • write a module extending some existing web server functionality (like mod_magnet does for Lighttpd), or

  • use some library that implements HTTP server functionality, so you just glue it with your language interpreter; I don't know any, but you can look at http://stackoverflow.com/questions/175507/c-c-web-server-library

But I think that programming language design is much harder task and requires more theoretical background than implementing a HTTP server, so... good luck :)

Messa
A: 

no matter what you want .. almost every webserver (assuming that i dont know about some) are programmed using sockets.. you will have to look into sockets first .. In Microsoft OSes you can use WINSOCK library .. though its kind of difficult to use at first , it will definitely teach you the core of networking ..

There are a number of other tools that you might want to try .. for example : .NET framework provides excellent socket implementation. For linux i guess there is POSIX api , if not you can always use Java sockets ..

There is an excellent book that you might want to read : "Computer Networking , A top down approach" .. The book has discussed in detail about webservers and even has a sample webserver coding meant for educating purposes.. Happy Programming ..

sp3tsnaz