예제 #1
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Console_WriteLine("MoonSharp REPL {0} [{1}]", Script.VERSION, Script.GlobalOptions.Platform.GetPlatformName());
            Console_WriteLine("Copyright (C) 2014-2015 Marco Mastropaolo");
            Console_WriteLine("http://www.moonsharp.org");
            Console_WriteLine();

            Console_WriteLine("Type Lua code in the text box below to execute it.");
            Console_WriteLine("The 'io', 'file' and parts of the 'os' modules are not available due to Silverlight restrictions.");
            Console_WriteLine("Type list() or list(<table>) to see which globals are available.");
            Console_WriteLine();
            Console_WriteLine("Welcome.");
            Console_WriteLine();

            script = new Script(CoreModules.Preset_Complete);

            script.DoString(@"
local function pad(str, len)
	str = str .. ' ' .. string.rep('.', len);
	str = string.sub(str, 1, len);
	return str;
end

function list(lib)
	if (lib == nil) then lib = _G; end

	if (type(lib) ~= 'table') then
		print('A table was expected to list command.');
		return
	end

	for k, v in pairs(lib) do
		print(pad(type(v), 12) .. ' ' .. k)
	end
end");

            script.Options.DebugPrint = s => Console_WriteLine(s);

            interpreter = new ReplHistoryInterpreter(script, 100)
            {
                HandleDynamicExprs       = true,
                HandleClassicExprsSyntax = true
            };


            DoPrompt();
        }