From 0587db3b1ecc176562eef19b8bfc4611763cfdbb Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sun, 3 Mar 2013 15:27:06 +0100 Subject: [PATCH] Update for nasal::Ghost changes --- src/GUI/FileDialog.cxx | 23 +++++------------------ src/GUI/FileDialog.hxx | 22 ++++++++++------------ src/Scripting/NasalCanvas.cxx | 24 ++++++++++-------------- 3 files changed, 25 insertions(+), 44 deletions(-) diff --git a/src/GUI/FileDialog.cxx b/src/GUI/FileDialog.cxx index c6a1c321f..33f10838b 100644 --- a/src/GUI/FileDialog.cxx +++ b/src/GUI/FileDialog.cxx @@ -86,18 +86,6 @@ void FGFileDialog::setShowHidden(bool show) _showHidden = show; } -naRef FGFileDialog::openFromNasal(const nasal::CallContext& ctx) -{ - exec(); - return naNil(); -} - -naRef FGFileDialog::closeFromNasal(const nasal::CallContext& ctx) -{ - close(); - return naNil(); -} - class NasalCallback : public FGFileDialog::Callback { public: @@ -133,21 +121,20 @@ private: int _gcKeys[2]; }; -naRef FGFileDialog::setCallbackFromNasal(const nasal::CallContext& ctx) +void FGFileDialog::setCallbackFromNasal(const nasal::CallContext& ctx) { // wrap up the naFunc in our callback type naRef func = ctx.requireArg(0); naRef object = ctx.getArg(1, naNil()); setCallback(new NasalCallback(func, object)); - return naNil(); } typedef boost::shared_ptr FileDialogPtr; typedef nasal::Ghost NasalFileDialog; /** - * Create new Canvas and get ghost for it. + * Create new FGFileDialog and get ghost for it. */ static naRef f_createFileDialog(naContext c, naRef me, int argc, naRef* args) { @@ -172,9 +159,9 @@ void postinitNasalGUI(naRef globals, naContext c) .member("show_hidden", &FGFileDialog::showHidden, &FGFileDialog::setShowHidden) .member("placeholder", &FGFileDialog::getPlaceholder, &FGFileDialog::setPlaceholderName) .member("pattern", &FGFileDialog::filterPatterns, &FGFileDialog::setFilterPatterns) - .method<&FGFileDialog::openFromNasal>("open") - .method<&FGFileDialog::closeFromNasal>("close") - .method<&FGFileDialog::setCallbackFromNasal>("setCallback"); + .method("open", &FGFileDialog::exec) + .method("close", &FGFileDialog::close) + .method("setCallback", &FGFileDialog::setCallbackFromNasal); nasal::Hash guiModule = nasal::Hash(globals, c).get("gui"); diff --git a/src/GUI/FileDialog.hxx b/src/GUI/FileDialog.hxx index 57fd89103..3479f8004 100644 --- a/src/GUI/FileDialog.hxx +++ b/src/GUI/FileDialog.hxx @@ -57,21 +57,19 @@ public: */ virtual ~FGFileDialog (); - virtual void exec() = 0; - virtual void close() = 0; + virtual void exec() = 0; + virtual void close() = 0; - class Callback - { - public: - virtual ~Callback() { } - virtual void onFileDialogDone(FGFileDialog* ins, const SGPath& result) = 0; - }; + class Callback + { + public: + virtual ~Callback() { } + virtual void onFileDialogDone(FGFileDialog* ins, const SGPath& result) = 0; + }; - virtual void setCallback(Callback* aCB); + virtual void setCallback(Callback* aCB); - naRef openFromNasal(const nasal::CallContext& ctx); - naRef closeFromNasal(const nasal::CallContext& ctx); - naRef setCallbackFromNasal(const nasal::CallContext& ctx); + void setCallbackFromNasal(const nasal::CallContext& ctx); protected: FGFileDialog(Usage use); diff --git a/src/Scripting/NasalCanvas.cxx b/src/Scripting/NasalCanvas.cxx index f349dadb5..fbb548b4f 100644 --- a/src/Scripting/NasalCanvas.cxx +++ b/src/Scripting/NasalCanvas.cxx @@ -178,13 +178,9 @@ naRef f_eventGetTarget(naContext c, sc::Event& event) return NasalElement::create(c, event.getTarget().lock()); } -// TODO allow directly exposing functions without parameters and return type -naRef f_eventStopPropagation(sc::Event& event, const nasal::CallContext& ctx) +void f_eventStopPropagation(sc::Event& event) { - if( ctx.argc != 0 ) - naRuntimeError(ctx.c, "Event::stopPropagation no argument expected"); event.stopPropagation(); - return naNil(); } naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave) @@ -192,7 +188,7 @@ naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave) NasalEvent::init("canvas.Event") .member("type", &sc::Event::getTypeString) .member("target", &f_eventGetTarget) - .method_func<&f_eventStopPropagation>("stopPropagation"); + .method("stopPropagation", &f_eventStopPropagation); NasalMouseEvent::init("canvas.MouseEvent") .bases() .member("screenX", &sc::MouseEvent::getScreenX) @@ -206,20 +202,20 @@ naRef initNasalCanvas(naRef globals, naContext c, naRef gcSave) .member("_node_ghost", &elementGetNode) .member("size_x", &sc::Canvas::getSizeX) .member("size_y", &sc::Canvas::getSizeY) - .method_func<&f_canvasCreateGroup>("_createGroup") - .method<&sc::Canvas::addEventListener>("addEventListener"); + .method("_createGroup", &f_canvasCreateGroup) + .method("addEventListener", &sc::Canvas::addEventListener); NasalElement::init("canvas.Element") .member("_node_ghost", &elementGetNode) - .method<&sc::Element::addEventListener>("addEventListener") - .method_func<&f_elementGetTransformedBounds>("getTransformedBounds"); + .method("addEventListener", &sc::Element::addEventListener) + .method("getTransformedBounds", &f_elementGetTransformedBounds); NasalGroup::init("canvas.Group") .bases() - .method_func<&f_groupCreateChild>("_createChild") - .method_func<&f_groupGetChild>("_getChild") - .method_func<&f_groupGetElementById>("_getElementById"); + .method("_createChild", &f_groupCreateChild) + .method("_getChild", &f_groupGetChild) + .method("_getElementById", &f_groupGetElementById); NasalText::init("canvas.Text") .bases() - .method_func<&f_textGetNearestCursor>("getNearestCursor"); + .method("getNearestCursor", &f_textGetNearestCursor); nasal::Hash globals_module(globals, c), canvas_module = globals_module.createHash("canvas");