--load external libraries: this one creates the evar table
require "evar";
require "args";
require "timer";

--open the lslua table containing functions like message_box(), etc
for k,v in pairs( lslua ) do _G[ k ] = v end

--call this with !lslua_test
function bang_lslua_test()
    --comments
    --[[ multi line
         comments ]]
    local my_string = "more stuff";
    local a_number = 5;
    if ( a_number ~= 6 ) then
        a_number = a_number + 1;
    end
    while ( a_number <= 100 ) do
        a_number = a_number * 2;
    end
    another_number, number_three = 2, 5;
    message_box( "stuff" );
    message_box( my_string );
    message_box( "$LiteStepDir$ = " .. evar.ls.LiteStepDir:toString() );
    message_box( do_some_calculations( a_number, 4.23 ), "Calculating... " );
    message_box( "\"This is a message box with quotes\"", "title" );
    exec( evar.ls.Browser:toString() );
    exec( evar.ls.LiteStepDir:toString() .. "step.rc" );
    exec( "\"explorer\" /e,c:\\" );
    exec( "explorer", "/e,c:\\Program Files\\" );
    exec( "!alert", "message", "title" );
    exec( "!about" );
    --message_box can have embedded quotes
end

--bangs can take arguments now! its just one big string that contains
--the entire argument string. use the 'args' package for parsing.
function bang_bang_with_args( param )
    for i, word in ipairs( args.qsplit( param ) ) do
        message_box( word );
    end
end

--you can define functions that don't get turned into bangs
function do_some_calculations( n, m )
    return n + m / 2;
end

function quote( string )
    return "\"" .. string .. "\"";
end

--any lua commands not in a function will be executed on module load
--this is useful for initializing variables and stuff like that, but nothing
--too complicated since lots of stuff will not be initialized yet
message_box( do_some_calculations( 3, 4 ) );
--define lslua.init() for *script start functionality
function lslua.init()
    exec( "!lslua_test" );
    timer.pause( "5s" );
    message_box( "done" );
end
--bang_lslua_test()
--these were not declared local in bang_lslua_test()
--message_box( another_number .. " " .. number_three );
--exec( "!alert \"This is a LiteStep !alert\"" );
--message_box( "This is an LSLua message_box()" );
