Corsix's blog

Ribbon (Summer of Code)

As some of you may know, this summer I've been participating in the Google Summer of Code, creating ribbon controls for wxWidgets.



A lot more pictures, along with details, in the full post.

Obfuscated Lua

I like Lua as a programming language for its beauty and simplicity, but sometimes you have to defile a language with horribly obfuscated code:

     L=           {}           for          k,v
     in          next          ,_G          ._G
     do          L[#k          ]=v          end
    L[10        ](([[p        =prin        t;for
   'q=99,      1,-1'do'      gg'q>1'      th{n'p(
  q.."'Bs'    {f'!:::'{n    'th{'<114    ,'"..q.."
 'Bs'of'!::  [.")gg'q>2't  h{n's=(q-1)  .."'Bs'{f'[
 !::'{n'th{  '<!+$."{lse'  s="1'B'{f'$  !::'{n'th{'
 <onx."{nd;  elsegg'q==1'  then'p"1'B'  {f'x!::'{n'
 th{'wall,'  1'B'of'[!::.  "s="no'mor{  '!::''{n'th
 e'<'!4!"en  d;p("Take'{n  {'down,'pas  s'it'around
 ,'"..s)p"-  "{nd]]):gsub  ("["..[==[$  4[]==]..[[x
 ]].."]",""  ):gsub([[B]]  ,"bottle"):  gsub("''?",
 " "):gsub(  "!:+","beer"  ):gsub("gg"  ,"if"):rep(
 3-2):gsub(  "<..","wall"  ):gsub("{",  function(_)
 B=((B)or(3  ))+1;return(  "eooe"):sub  (B%4+1,(B+1
 +2+9)%4+(#  L[1]-13),(B*  2)%7)end))(  L[#L]or...)

Despite what it looks like, it is valid Lua 5.1 code. If it isn't immediately obvious what it does, then you can see the output.

Try Lua

The end product of a few days of hacking together code: an interactive Lua terminal, in the browser, via AJAX magic.

The javascript side was lovingly ripped from the TryRuby site (as it is conveniently BSD licensed). The server side is implemented using Apache, mod_lua, a custom "persistent Lua" C module and some Lua scripts.

Feel free to try it out, but remember that it is currently very crude and at the technical proof of concept stage, rather than nice user friendly stage.

mod_lua on win32

mod_lua (what was mod_wombat, and is part of Apache core since version 2.3) is something which I'd quite like to work with for Google Summer of Code 2009. In order to work on it, you first need to be able to compile and run it. Doing this on linux is trivial - checkout the svn head of httpd, ./configure (with appropriate command line arguments), make and then sudo make install. Doing so on Windows is less trivial, but it can be done.

For my Windows setup, I've got a standard binary distribution of win32 Apache 2.2.9 (complete with development include and library files) running on Vista. This makes things slightly more interesting, as mod_lua targets Apache 2.3 and above, but I can't find win32 binary distributions of 2.3, nor do I feel confident in compiling it under windows. From this baseline, I did the following:

  1. Checkout the mod_lua svn trunk (using TortoiseSVN)
  2. Create a new Visual Studio project and add all of the mod_lua source files
  3. Add additional include directories ("E:\CPP\lua-5.1.4\src";"C:\Program Files\Apache Software Foundation\Apache2.2\include")
  4. Add LUA_DECLARE_EXPORT to the preprocessor definitions
  5. Add additional library directories ("C:\Program Files\Apache Software Foundation\Apache2.2\lib";"E:\CPP\lua-5.1.4\Debug")
  6. Add lua5.1.lib, libapr-1.lib, libaprutil-1.lib and libhttpd.lib to the library list
  7. Add a post-build event to copy the resultant DLL to the modules folder (cp "$(OutDir)\$(ProjectName).dll" "C:\Program Files\Apache Software Foundation\Apache2.2\modules\mod_lua.so")
  8. Fix the usage of AP_DECLARE and AP_DECLARE_LUA throughout the codebase (patch available on the httpd-dev mailing list)
  9. Copy the ap_args_to_table and ap_body_to_table functions over from Apache 2.3's util_script.c into a new file, util_script_ap23.c. This is compilcated due to ap_body_to_table's usage of the request_req::body_table field, which is not present in the 2.2 version - but can be worked around via usage of apr_pool_userdata_[sg]et with the request's pool.
  10. Compile the project and tweak httpd.conf as required to load and configure the module

mod_lua on win32/Apache2.2
(for comparison, similar info screenshot on the linux build)

HexEditIX, part 2

So, time for the daily development screenshot:

Syndicate content