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.

First of all, some Windows screenshots showing how things "collapse" as the ribbon width decreases:






In the above screenshot, the width is so small that some of the panels have "minimised", at which point the user can expand them when they want to use them:

At even smaller resolutions, scroll buttons are used:

The above screenshots contain the wxRibbonToolBar (on the left-most panel) and wxRibbonButtonBar (on the middle two panels). The other interesting widget is wxRibbonGallery (on the right two panels):

All of the ribbon controls are custom painted, allowing the colour scheme to be radically changed at runtime:



As well as mere colour changes, the entire art provider can be changed. All of the above screenshots are using the MSW art provider, which is based on the art style used in Microsoft Office. An alternative to that is the AUI art provider, which is based on the art style of wxAUI:

Like the MSW provider, the AUI provider can also adopt other colour schemes:

While the preferred state is to have the ribbon at the top of the window, it can also be positioned on the left:





One of wxWidget's strengths is in being cross platform. As such, a batch of screenshots wouldn't be complete without some Linux screenshots:





The MSW art style can still be used on Linux, as shown:

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.

The overall form of the code is loadstring(([[code]]):decrypt())(). Of course, putting a straight loadstring call into the code would make things obvious (and it would break the nice formatting). Hence there is this lovely piece of code instead:

L = {}
for key, value in pairs(_G) do
  L[#key] = value
end
-- L[10] is now loadstring (and L[1] is L)

This relies on the fact that loadstring is the only global variable whose name is 10 characters long:

LengthGlobals
1L
2_G os
4load math type next
5debug error pairs pcall print table
6dofile ipairs module rawget rawset select string unpack xpcall
7getfenv package require setfenv
8_VERSION loadfile newproxy tostring
9coroutine
10loadstring
12getmetatable setmetatable
14collectgarbage
Next comes a long string containing the true program code (although not in plaintext), and then after it come a number of calls to string.gsub to turn the string back into valid Lua code. The calls to gsub are:
PatternReplacement
[$4[x%s](nothing)
Bbottle
''?(space)
!:+beer
ggif
<..wall
{
function()
  B = (B or 3) + 1
  return ("eooe"):sub((B % 4) + 1, (B % 4) + 1)
end

After all of these replacements, the code that gets send to loadstring is: (linebreaks and indentation added for clarity)

p=print;
for q=99,1,-1 do
  if q>1 then
    p(q.." bottles of beer on the wall, "..q.." bottles of beer.")
    if q>2 then
      s=(q-1).." bottles of beer on the wall."
    else
      s="1 bottle of beer on the wall."
    end;
  elseif q==1 then
    p"1 bottle of beer on the wall, 1 bottle of beer."
    s="no more beer on the wall!"
  end;
  p("Take one down, pass it around, "..s)
  p"-"
end

This code is loaded, and then executed, and the result is (obviously) the 99 bottles of beer song.

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:

page: 17 18 19 20 21