Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

No longer require new(Class(...)) to create objects.

  • Loading branch information...
commit 81c51d9557faa89f987b11e8b100d0e052c7d7aa 1 parent d5f9b98
@alecthomas authored
Showing with 24 additions and 8 deletions.
  1. +14 −4 oink.js
  2. +10 −4 oink.py
View
18 oink.js
@@ -1,3 +1,8 @@
+// The Oink runtime.
+//
+// Contains the base of all classes, builtin functions, helper functions, etc.
+//
+
// Originally from http://ejohn.org/blog/simple-javascript-inheritance/
// Inspired by base2 and Prototype
(function(){
@@ -44,10 +49,11 @@
}
// The dummy class constructor
- function Class() {
+ function Class(args) {
// All construction is actually done in the __init__ method
- if (!initializing && this.__init__)
- this.__init__.apply(this, arguments);
+ if (!initializing && this.__init__) {
+ this.__init__.apply(this, args);
+ }
}
// Populate our constructed prototype object
@@ -58,8 +64,12 @@
// And make this class extendable
Class.extend = arguments.callee;
+
+ function constructor() {
+ return new Class(arguments);
+ }
- return Class;
+ return constructor;
};
Oink.str = function (subject) {
View
14 oink.py
@@ -450,12 +450,11 @@ class Global(PyV8.JSClass):
help='path to runtime [%default]')
parser.add_option('--runtime', default='oink.js',
help='files to include in runtime [%default]')
+ parser.add_option('--run', action='store_true',
+ help='attempt to run the compiled script')
options, args = parser.parse_args()
- runtime = [os.path.join(options.include, p)
- for p in options.runtime.split(',')]
-
if not args:
parser.error('python source file required')
filename = args[0]
@@ -467,4 +466,11 @@ class Global(PyV8.JSClass):
except Error, e:
print >> sys.stderr, 'error: %s:%s' % (filename, e)
sys.exit(1)
- print script
+
+ if options.run:
+ runtime = [os.path.join(options.include, p)
+ for p in options.runtime.split(',')]
+ runtime = '\n'.join(open(f).read() for f in runtime)
+ run_script(runtime + '\n' + script)
+ else:
+ print script
Please sign in to comment.
Something went wrong with that request. Please try again.