Permalink
Browse files

merge optional_args branch, fix conflicts

  • Loading branch information...
2 parents 1b518b2 + a30588d commit 62477478cbb41c1787149b696cd63ed252859e95 @Whiteknight committed Mar 21, 2012
View
@@ -17,18 +17,13 @@ namespace Rosella
/* Constructor
*/
- function Action(var method,
- var args [optional], int has_args [opt_flag])
+ function Action(var method, var args = [])
{
if (method == null)
Rosella.Error.invalid(__FUNCTION__, "Subroutine is null");
self.method = method;
- if (has_args) {
- using Rosella.Action.Argument.verify_all_arguments;
- verify_all_arguments(__FUNCTION__, args);
- self.args = args;
- } else
- self.args = [];
+ Rosella.Action.Argument.verify_all_arguments(__FUNCTION__, args);
+ self.args = args;
}
/* Public Functions
@@ -38,14 +33,12 @@ namespace Rosella
// arguments and a hash of named arguments. In addition to the
// pre-defined Argument objects, take an optional list of Argument
// overrides.
- function prepare_args(var pos, var named,
- var overrides [optional], int has_overrides [opt_flag])
+ function prepare_args(var pos, var named, var overrides = null)
{
for (var arg in self.args)
arg.resolve_to(pos, named);
- if (has_overrides) {
- using Rosella.Action.Argument.verify_all_arguments;
- verify_all_arguments(__FUNCTION__, overrides);
+ if (overrides != null) {
+ Rosella.Action.Argument.verify_all_arguments(__FUNCTION__, overrides);
for (var override in overrides)
override.resolve_to(pos, named);
}
@@ -54,12 +47,10 @@ namespace Rosella
// Execute the action on the given object. Take an optional list of
// Argument overrides to change the default behavior.
function execute(var obj,
- var overrides [optional], int has_overrides [opt_flag])
+ var overrides = [])
{
var pos = [];
var named = {};
- if (!has_overrides)
- overrides = [];
self.prepare_args(pos, named, overrides);
self.execute_initializer(obj, pos, named);
}
@@ -235,10 +235,10 @@ class Rosella.CommandLine.Arguments
}
// Fetch a positional argument, which may be a flag or anything else.
- function fetch_positional(string name, int keep, int idx [optional], int has_idx [opt_flag])
+ function fetch_positional(string name, int keep, int idx = -1)
{
string arg = "";
- if (has_idx) {
+ if (idx >= 0) {
if (idx >= elements(self.args)) {
self.cache[name] = "";
return "";
View
@@ -30,9 +30,7 @@ namespace Rosella.IO
return save_handles;
}
- // Execute a callback, capturing all output to the standard output handles
- function capture_output(int together, var func,
- var err_func [optional], int has_err [opt_flag])
+ function capture_output(int together, var func, var err_func = null)
{
var stdout = new "StringHandle";
stdout.open("blah", "rw");
@@ -52,23 +50,20 @@ namespace Rosella.IO
exception = e;
}
swap_handles(save_handles);
- if (exception != null && has_err && err_func != null)
+ if (exception != null && err_func != null)
err_func(exception);
if (together)
return stdout;
else
return stdout, stderr;
}
- // Execute a commandline command, returning the output text. If the command
- // fails, optionally execute an error handling callback.
- function execute_pipe(string cmd,
- var on_err [optional], int has_err [opt_flag])
+ function execute_pipe(string cmd, var on_err = null)
{
var pipe = open_pipe(cmd);
string output = pipe.readall();
int exit_status = close_pipe(pipe);
- if (exit_status != 0 && has_err && on_err != null)
+ if (exit_status != 0 && on_err != null)
on_err(exit_status);
return output;
}
@@ -11,12 +11,9 @@ class Rosella.ObjectFactory
{
var target_type;
- function ObjectFactory(var target_type [optional], int has_type [opt_flag])
+ function ObjectFactory(var target_type = null)
{
- if (has_type)
- self.target_type = target_type;
- else
- self.target_type = null;
+ self.target_type = target_type;
}
// If the default target type is set, call .create_typed with it.
View
@@ -45,10 +45,9 @@ namespace Rosella.Parrot
// Execute a function. Catch any exceptions and print the message and
// backtrace out to a specified handle. If no handle is specified,
// use stdout.
- function try_report(var sub, var handle [optional],
- int has_handle [opt_flag])
+ function try_report(var sub, var handle = null)
{
- if (!has_handle)
+ if (handle == null)
handle = getstdout();
try {
sub();
View
@@ -155,11 +155,10 @@ namespace Rosella
}
// Load in the bytecode library, executing the given trigger, if any.
- function load_bytecode_file(string file,
- string trigger [optional], int has_trigger [opt_flag])
+ function load_bytecode_file(string file, string trigger = null)
{
var pf = load_packfile(file);
- if (has_trigger && trigger != "" && trigger != null)
+ if (trigger != "" && trigger != null)
init_bytecode(pf, trigger);
return pf;
}
View
@@ -83,10 +83,8 @@ class Rosella.Dumper
}
// Add a new type dumper to the list
- function add_type_dumper(var type, var dumper [optional], int has_dumper [opt_flag])
+ function add_type_dumper(var type, var dumper = new Rosella.Dumper.DumpHandler())
{
- if (!has_dumper)
- dumper = new Rosella.Dumper.DumpHandler();
self.type_dumpers[type] = dumper;
}
@@ -17,7 +17,7 @@ namespace Rosella.FileSystem.Directory
class Rosella.FileSystem.Directory : Rosella.FileSystem.Entry
{
// Constructor. Build a directory with the given path name
- function Directory(string path, var parent_dir [optional], int has_parent [opt_flag])
+ function Directory(string path, var parent_dir = null)
{
if (path == null || path == "")
Rosella.Error.error("Directory needs a valid path");
@@ -27,7 +27,7 @@ class Rosella.FileSystem.Directory : Rosella.FileSystem.Entry
string lastchar = substr(path, len - 1);
if (lastchar != path_sep)
path = path + path_sep;
- if (has_parent)
+ if (parent_dir != null)
path = string(parent_dir) + path;
self.Entry(path);
}
@@ -72,11 +72,8 @@ class Rosella.FileSystem.Directory : Rosella.FileSystem.Entry
}
// Walk this directory recursively using a Visitor object.
- function walk(var visitor [optional], int has_v [opt_flag])
+ function walk(var visitor = new Rosella.FileSystem.Visitor.List())
{
- if (!has_v)
- visitor = new Rosella.FileSystem.Visitor.List();
-
visitor.begin_directory(self);
var files = self.get_files();
for (var file in files)
View
@@ -31,20 +31,20 @@ namespace Rosella.FileSystem.File
class Rosella.FileSystem.File : Rosella.FileSystem.Entry
{
// Constructor
- function File(string filepath, var parent_dir [optional], int has_dir [opt_flag])
+ function File(string filepath, var parent_dir = null)
{
- if (has_dir)
+ if (parent_dir != null)
filepath = string(parent_dir) + filepath;
self.Entry(filepath);
}
// Open the file for reading, returning the open FileHandle. The user
// must close the filehandle themselves.
- function open_read(string encoding [optional], int has_e [opt_flag])
+ function open_read(string encoding = null)
{
int is_binary = 0;
var filehandle = get_filehandle();
- if (has_e) {
+ if (encoding != null) {
string mode = (encoding == "binary") ? "rb" : "r";
filehandle.open(self.path, mode);
filehandle.encoding(encoding);
@@ -55,10 +55,10 @@ class Rosella.FileSystem.File : Rosella.FileSystem.Entry
// Open the file for writing, returning the open FileHandle. The user
// must close the FileHandle themselves.
- function open_write(string encoding [optional], int has_e [opt_flag])
+ function open_write(string encoding = null)
{
var filehandle = get_filehandle();
- if (has_e) {
+ if (encoding != null) {
string mode = (encoding == "binary") ? "wb" : "w";
filehandle.open(self.path, mode);
filehandle.encoding(encoding);
@@ -76,10 +76,10 @@ class Rosella.FileSystem.File : Rosella.FileSystem.Entry
}
// Return all text from the file in a single string.
- function read_all_text(string encoding [optional], int has_e [opt_flag])
+ function read_all_text(string encoding = null)
{
var filehandle;
- if (has_e && encoding != null)
+ if (encoding != null)
filehandle = self.open_read(encoding);
else
filehandle = self.open_read();
View
@@ -60,11 +60,14 @@ class Rosella.Harness
return self;
}
+ function set_view(var view)
+ {
+ self.view = view;
+ }
+
// Set a view to use
- function view(var view [optional], int has_view [opt_flag])
+ function view()
{
- if (has_view)
- self.view = view;
if (self.view == null)
self.view = new Rosella.Harness.View();
return self.view;
@@ -90,11 +93,8 @@ class Rosella.Harness
}
// Return the current test run
- function setup_test_run(var view [optional], int has_view [opt_flag],
- var options [named,slurpy])
+ function setup_test_run(var view = self.view(), var options [named,slurpy])
{
- if (!has_view || view == null)
- view = self.view();
var run = self.testrun_factory.create(options:[flat,named]);
view.add_run(run, 0);
push(self.saved_runs, run);
@@ -111,17 +111,15 @@ class Rosella.Harness
*/
// Run the harness. Get argument values and pass them to run_internal
- function run(var test_runs [optional], int has_runs [opt_flag],
+ function run(var test_runs = self.saved_runs,
var test_executor [named,optional], int has_te [opt_flag],
int debug [named,optional], int has_dbg [opt_flag])
{
if (!has_te)
test_executor = self.container.resolve(class Rosella.Harness.TestExecutor);
if (!has_dbg)
debug = 0;
- if (has_runs == false || test_runs == null || elements(test_runs) == 0)
- test_runs = self.saved_runs;
- else if (has_runs == true && test_runs instanceof Rosella.Harness.TestRun)
+ if (test_runs instanceof Rosella.Harness.TestRun)
test_runs = [test_runs];
var fileresult_factory = self.container.resolve(class Rosella.Harness.FileResult.Factory);
View
@@ -17,11 +17,9 @@ class Rosella.Harness.View
var need_backspaces;
// Constructor
- function View(var handle [optional], int has_h [opt_flag])
+ function View(var handle = null)
{
- if (!has_h)
- handle = getstdout();
- self.handle = handle;
+ self.handle = handle == null ? getstdout() : handle;
self.test_runs = [];
self.line_length = 0;
self.total_files = 0;
View
@@ -1,21 +1,21 @@
namespace Rosella.Dumper {
- class DumpHandler;
- class Emitter;
- class Handle;
- extern function default_dumper;
- extern function set_default_dumper;
+ class DumpHandler;
+ class Emitter;
+ class Handle;
+ extern function default_dumper;
+ extern function set_default_dumper;
}
namespace Rosella {
- class Dumper;
+ class Dumper;
}
namespace Rosella.Dumper.DumpHandler {
- class Array;
- class Hash;
- class InspectAttrs;
- class Object;
- class Null;
+ class Array;
+ class Hash;
+ class InspectAttrs;
+ class Object;
+ class Null;
}
function __include_dumper [anon] ()
View
@@ -1,25 +1,25 @@
namespace Rosella.Event {
- class Dispatcher;
- class Manager;
- class Payload;
- class Subscriber;
- extern function default_subscriber_factory;
- extern function payload_factory;
+ class Dispatcher;
+ class Manager;
+ class Payload;
+ class Subscriber;
+ extern function default_subscriber_factory;
+ extern function payload_factory;
}
namespace Rosella {
- class Event;
+ class Event;
}
namespace Rosella.Event.Dispatcher {
- class Immediate;
- class Task;
- class Thread;
- class Factory;
+ class Immediate;
+ class Task;
+ class Thread;
+ class Factory;
}
namespace Rosella.Event.Subscriber {
- class Factory;
+ class Factory;
}
function __include_event [anon] ()
Oops, something went wrong.

0 comments on commit 6247747

Please sign in to comment.