Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'new-api'
Browse files Browse the repository at this point in the history
Signed-off-by: WebFreak001 <[email protected]>

Conflicts:
	source/com/dub.d
  • Loading branch information
WebFreak001 committed Jan 7, 2016
2 parents fa747ea + f89dcf1 commit 4c53674
Show file tree
Hide file tree
Showing 8 changed files with 901 additions and 677 deletions.
74 changes: 74 additions & 0 deletions source/api.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module workspaced.api;

import std.conv;
import std.json;
import painlessjson;

///
alias AsyncCallback = void delegate(Throwable, JSONValue);

/// Will get called asynchronously (Must prepend AsyncCallback as argument)
enum async = 2603248026;

/// Will get called for loading components
enum load = 2603248027;

/// Will get called for unloading components
enum unload = 2603248028;

/// Will call this function in any case (cmd: component)
enum any = 2603248029;

/// Component call
struct component
{
/// Name of the component
string name;
}

/// Will get called when some argument matches
struct Arguments
{
/// Arguments to match
Argument[] arguments;
}

private struct Argument
{
/// Key in JSON object node at root level to match
string key;
/// Value in JSON object node at root level to match
JSONValue value;
}

private template ArgumentPair(size_t i)
{
static if (i > 0)
enum ArgumentPair = "ret.arguments[" ~ (i / 2 - 1).to!string ~ "] = Argument(args[" ~ (i - 2).to!string ~ "], args[" ~ (i - 1).to!string ~ "].toJSON);" ~ ArgumentPair!(
i - 2);
else
enum ArgumentPair = "";
}

Arguments arguments(T...)(T args)
{
if (args.length < 2)
return Arguments.init;
Arguments ret;
ret.arguments.length = args.length / 2;
mixin(ArgumentPair!(args.length));
return ret;
}

unittest
{
Arguments args = arguments("foo", 5, "bar", "str");
assert(args.arguments[0].key == "foo");
assert(args.arguments[0].value.integer == 5);
assert(args.arguments[1].key == "bar");
assert(args.arguments[1].value.str == "str");
}

alias ImportPathProvider = string[]function();

ImportPathProvider importPathProvider, stringImportPathProvider;
Loading

0 comments on commit 4c53674

Please sign in to comment.