Skip to content

Commit

Permalink
Update to latest candor and use varargs syntax in OOP example
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Mar 25, 2012
1 parent 4ff9a97 commit 02c8a8b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/cio_libs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
2 changes: 1 addition & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
18 changes: 12 additions & 6 deletions test-objects.can
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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.