Skip to content

Commit

Permalink
Add alloy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Roesslein committed Nov 23, 2010
1 parent b421c71 commit 41a9de1
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools/alloy/Resources/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>

<head>
</head>

<body>
</body>

</html>
14 changes: 14 additions & 0 deletions tools/alloy/manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#appname:Alloy
#version:1.0
#appid:com.titaniumapp.alloy
#publisher:Appcelerator
#image:default_app_logo.png
#url:http://titaniumapp.com
#guid:be69fe4c-966b-483c-b57c-7ba4a34fbf10
#desc:Alloy shell
runtime:
python:
ruby:
alloy:
tiapp:
#php:
81 changes: 81 additions & 0 deletions tools/alloy/modules/alloy/alloymodule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
(function(){
Titanium.API.setLogLevel(Titanium.API.ERROR);

var stdout = Titanium.App.stdout;
var stdin = Titanium.App.stdin;

String.prototype.rtrim=function(){return this.replace(/\s+$/,'');}
String.prototype.endsWith = function endsWith(pattern)
{
var d = this.length - pattern.length;
return d >= 0 && this.lastIndexOf(pattern) === d;
}

stdout("~~~~~Alloy~~~~~");
stdout("Type /<language name> to switch languages");
stdout("Supported languages: javascript, python, ruby");
stdout("For multi-line blocks of code, use a \\ to continue on a newline");
stdout("Type /exit to quit");
stdout("");

var langEvals = {
javascript: function(mimeType, scriptName, code, globals)
{
try
{
eval(code);
}
catch(e)
{
stdout("Javascript error: " + e);
}
},
python: Titanium.Python.evaluate,
ruby: Titanium.Ruby.evaluate,
};

var activeEval = langEvals["javascript"];
var activeMime = "text/javascript";
var command = "";
while (true)
{
command += stdin(">>> ").rtrim();
if (command == "/exit")
{
break;
}
else if (command.charAt(0) == '/')
{
// Switch languages
var lang = command.substr(1).toLowerCase();
var langEval = langEvals[lang];
if (langEval != undefined)
{
activeMime = "text/" + lang;
activeEval = langEvals[lang];
}
else
{
stdout("Invalid language: " + lang);
}
}
else if (command.endsWith("\\"))
{
// multi-line code
command = command.substring(0, command.length - 1) + "\n";
continue;
}
else
{
// evalute it as code
var result = activeEval(activeMime, "alloy", command, this);
if (result != undefined)
{
stdout(result);
}
}
command = "";
}

Titanium.App.exit();
})();
9 changes: 9 additions & 0 deletions tools/alloy/tiapp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
<ti:app xmlns:ti='http://ti.appcelerator.org'>
<id>com.titaniumapp.alloy</id>
<name>Alloy</name>
<version>1.0</version>
<publisher>Appcelerator</publisher>
<url>titaniumapp.com</url>
<copyright>2009 by Appcelerator</copyright>
</ti:app>

0 comments on commit 41a9de1

Please sign in to comment.