# A polyglot program that runs in either Python or Lua. x = 1 or 1 -- """ Begin a Python/Ruby multiline string inside a Lua comment. -- In Python or Ruby, the expression parses as 1 or (1 - (- 'some string')). -- As it happens, strings don't have an unary minus operator defined for them, -- and if they did, its result probably couldn't be subtracted from 1. -- But that would only matter if the second half of the 'or' expression -- were to be evaluated. And it's not. -- The 'x =' part is to make the expression '1 or 1' into a statement -- in Lua, which doesn't have expression statements. -- See http://codegambler.wordpress.com/2009/10/04/polyglotsingle-program-runs-on-multiple-languages/ -- and http://osdc.tw/2010/02/schedule_polyglot_programming.html -- and http://www.nyx.net/~gthompso/poly/polyglot.htm -- for techniques that might permit adding some other languages. print('hello, world, from Lua!') x = [[ " # end the Ruby (but not the Python) multiline string inside a Lua multiline string. # Now, until we do it again, Python and Ruby are out of phase. # Thanks to http://www.riffraff.info/2009/1/16/life-polyglot-ruby-python for the technique! puts 'hello, world, from Ruby!' """ print 'hello, world, from Python!' #"#]] -- end the Ruby multiline string inside a Python comment and the Lua multiline string inside a Python/Ruby comment.