Permalink
Browse files

Implement binders for BUF3 and BUF4

  • Loading branch information...
1 parent 86aced7 commit 2e11d526bc20c659f33df5962a7bcb946b497323 @jmendeth jmendeth committed Aug 24, 2012
Showing with 36 additions and 0 deletions.
  1. +36 −0 src/robotskirt.cc
View
@@ -373,6 +373,42 @@ WRAPPERS(BUF4)
return BINDER_RETURN_##RET; \
}
+#define BUF3_BINDER(CPPFUNC, RET) \
+ static RET CPPFUNC##_binder(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque) {\
+ HandleScope scope; \
+ \
+ /*Convert arguments*/ \
+ Local<Value> args [2] = {toString(text), toString(lang)}; \
+ \
+ /*Call it!*/ \
+ TryCatch trycatch; \
+ Local<Value> ret = ((RendererData*)opaque)->CPPFUNC->CallAsFunction(Context::GetCurrent()->Global(), 2, args);\
+ if (trycatch.HasCaught()) \
+ V8_THROW(trycatch.Exception()); \
+ /*Convert the result back*/ \
+ if (ret->IsFalse()) return BINDER_RETURN_NULL_##RET; \
+ putToBuf(ob, ret); \
+ return BINDER_RETURN_##RET; \
+ }
+
+#define BUF4_BINDER(CPPFUNC, RET) \
+ static RET CPPFUNC##_binder(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *cont, void *opaque) {\
+ HandleScope scope; \
+ \
+ /*Convert arguments*/ \
+ Local<Value> args [3] = {toString(link), toString(title), toString(cont)};\
+ \
+ /*Call it!*/ \
+ TryCatch trycatch; \
+ Local<Value> ret = ((RendererData*)opaque)->CPPFUNC->CallAsFunction(Context::GetCurrent()->Global(), 3, args);\
+ if (trycatch.HasCaught()) \
+ V8_THROW(trycatch.Exception()); \
+ /*Convert the result back*/ \
+ if (ret->IsFalse()) return BINDER_RETURN_NULL_##RET; \
+ putToBuf(ob, ret); \
+ return BINDER_RETURN_##RET; \
+ }
+
// FORWARDERS (forward a Sundown call to its original C++ renderer)
#define BUF1_FORWARDER(CPPFUNC, RET) \

0 comments on commit 2e11d52

Please sign in to comment.