diff src/c/urweb.c @ 1334:a1aa62b472cf

Change Basis.debug to use the protocol's debug function
author Adam Chlipala <adam@chlipala.net>
date Sun, 12 Dec 2010 10:35:04 -0500
parents 4dd5d23bace2
children b106ca8200b1
line wrap: on
line diff
--- a/src/c/urweb.c	Sat Dec 11 19:57:22 2010 -0500
+++ b/src/c/urweb.c	Sun Dec 12 10:35:04 2010 -0500
@@ -442,6 +442,9 @@
 
   void *client_data;
 
+  void *logger_data;
+  uw_logger log_debug;
+
   char error_message[ERROR_BUF_LEN];
 };
 
@@ -450,7 +453,7 @@
 size_t uw_heap_max = SIZE_MAX;
 size_t uw_script_max = SIZE_MAX;
 
-uw_context uw_init() {
+uw_context uw_init(void *logger_data, uw_logger log_debug) {
   uw_context ctx = malloc(sizeof(struct uw_context));
 
   ctx->app = NULL;
@@ -501,6 +504,9 @@
 
   ctx->client_data = uw_init_client_data();
 
+  ctx->logger_data = logger_data;
+  ctx->log_debug = log_debug;
+
   return ctx;
 }
 
@@ -3441,8 +3447,10 @@
 size_t uw_database_max = SIZE_MAX;
 
 uw_Basis_unit uw_Basis_debug(uw_context ctx, uw_Basis_string s) {
-  fprintf(stderr, "%s\n", s);
-
+  if (ctx->log_debug)
+    ctx->log_debug(ctx->logger_data, "%s\n", s);
+  else
+    fprintf(stderr, "%s\n", s);
   return uw_unit_v;
 }