From 53f355e41d87c2010b2a2ff78de77f1a6379188b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 26 Oct 2016 02:40:55 -0700 Subject: [PATCH] modules: Add preliminary console to support js-style console.log() et al. --- modules/Makefile.am | 2 ++ modules/console.cc | 70 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 modules/console.cc diff --git a/modules/Makefile.am b/modules/Makefile.am index 5335fce93..cea57aaa0 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -40,6 +40,7 @@ conf_module_LTLIBRARIES = \ moduledir=@moduledir@ future_la_SOURCES = future.cc require_la_SOURCES = require.cc +console_la_SOURCES = console.cc m_host_la_SOURCES = m_host.cc m_get_la_SOURCES = m_get.cc #m_ban_la_SOURCES = m_ban.cc @@ -129,6 +130,7 @@ m_get_la_SOURCES = m_get.cc module_LTLIBRARIES = \ future.la \ require.la \ +console.la \ m_host.la \ m_get.la diff --git a/modules/console.cc b/modules/console.cc new file mode 100644 index 000000000..0934313d2 --- /dev/null +++ b/modules/console.cc @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 Charybdis Development Team + * Copyright (C) 2016 Jason Volk + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice is present in all copies. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +namespace ircd { +namespace js { + +struct console +:trap +{ + using trap::trap; +} +static console{"console"}; + +struct console_log +:trap::function +{ + value on_call(object::handle obj, value::handle _this, const args &args) override + { + ircd::js::log.info("%s", string(args[0]).c_str()); + return {}; + } + + using trap::function::function; +} +static console_log{console, "log"}; + +struct console_error +:trap::function +{ + value on_call(object::handle obj, value::handle _this, const args &args) override + { + ircd::js::log.error("%s", string(args[0]).c_str()); + return {}; + } + + using trap::function::function; +} +static console_error{console, "error"}; + +} // namespace js +} // namespace ircd + +using namespace ircd::js; +using namespace ircd; + +mapi::header IRCD_MODULE +{ + "Provides simple I/O for debugging similar to that found in web browsers.", + mapi::NO_FLAGS +};