Permalink
Browse files

Update to latest candor and use varargs syntax in OOP example

  • Loading branch information...
creationix committed Mar 25, 2012
1 parent 4ff9a97 commit 02c8a8b67b9871ba79254a6ade3fc2c6be5e8f89
Showing with 15 additions and 9 deletions.
  1. +1 −1 deps/candor
  2. +1 −1 src/cio_libs.cc
  3. +1 −1 src/main.cc
  4. +12 −6 test-objects.can
View
@@ -19,7 +19,7 @@ Object* cio_##name##_module() { \
char* code = &_binary_lib_##name##_can_start; \
int len = &_binary_lib_##name##_can_end - \
&_binary_lib_##name##_can_start; \
- Function* fn = Function::New(code, len); \
+ Function* fn = Function::New(#name, code, len);\
fn->SetContext(cio_global_context()); \
module_##name.Wrap(fn->Call(0, NULL)); \
return *module_##name; \
View
@@ -52,7 +52,7 @@ int main(int argc, char** argv) {
// Load script and run
off_t size = 0;
const char* script = ReadContents(argv[1], &size);
- Function* code = Function::New(script, size);
+ Function* code = Function::New(argv[1], script, size);
delete script;
if (isolate.HasError()) {
View
@@ -1,7 +1,15 @@
print = global.print
p = global.prettyPrint
-Rectangle = {}
+Object = {
+ "new": (self, args...) {
+ obj = new self
+ if (obj.initialize) obj:initialize(args...)
+ return obj
+ }
+}
+
+Rectangle = new Object
Rectangle.getArea = (self) {
return self.w * self.h
}
@@ -18,12 +26,10 @@ Square.initialize = (self, s) {
}
p("Square", Square)
-rect = new Rectangle
-rect:initialize(3, 5)
+rect = Rectangle:new(3, 5)
p("rect", rect)
print("Rectangle 3x5 = " + rect:getArea())
-square = new Square
-square:initialize(4)
+square = Square:new(4)
p("square", square)
-print("Square 4x4 = " + square:getArea())
+print("Square 4x4 = " + square:getArea())

0 comments on commit 02c8a8b

Please sign in to comment.