From 08799499047026095fb38efd55c1e3ff29b0dd6b Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 27 Feb 2018 13:52:05 -0500 Subject: [PATCH] Register translation functions for Nyquist effects into XLisp runtime --- src/effects/nyquist/Nyquist.cpp | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index 2924520ec..36d45b676 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -554,8 +554,12 @@ bool NyquistEffect::CheckWhetherSkipEffect() return (mIsPrompt && mControls.size() > 0); } +static void RegisterFunctions(); + bool NyquistEffect::Process() { + RegisterFunctions(); + bool success = true; mProjectChanged = false; @@ -2532,3 +2536,39 @@ void NyquistOutputDialog::OnOk(wxCommandEvent & /* event */) EndModal(wxID_OK); } +// Registration of extra functions in XLisp. +#include "../../../lib-src/libnyquist/nyquist/xlisp/xlisp.h" + +static LVAL gettext() +{ + auto string = UTF8CTOWX(getstring(xlgastring())); + xllastarg(); + return cvstring(GetCustomTranslation(string).mb_str(wxConvUTF8)); +} + +static LVAL ngettext() +{ + auto string1 = UTF8CTOWX(getstring(xlgastring())); + auto string2 = UTF8CTOWX(getstring(xlgastring())); + auto number = getfixnum(xlgafixnum()); + xllastarg(); + return cvstring( + wxGetTranslation(string1, string2, number).mb_str(wxConvUTF8)); +} + +static void RegisterFunctions() +{ + // Add functions to XLisp. Do this only once, + // before the first call to nyx_init. + static bool firstTime = true; + if (firstTime) { + firstTime = false; + + static const FUNDEF functions[] = { + { "_", SUBR, gettext }, + { "ngettext", SUBR, ngettext }, + }; + + xlbindfunctions( functions, sizeof(functions)/sizeof(*functions) ); + } +}