diff --git a/plugins/script/Makefile.am b/plugins/script/Makefile.am index 7aac76f7..ad136efb 100644 --- a/plugins/script/Makefile.am +++ b/plugins/script/Makefile.am @@ -22,3 +22,7 @@ EXTRA_DIST = genmeta.py momscript-classes-meta.h: momscript-classes.h genmeta.py $(PYTHON) $(srcdir)/genmeta.py $(srcdir)/momscript-classes.h > momscript-classes-meta.h.tmp && \ mv momscript-classes-meta.h.tmp momscript-classes-meta.h + +momscript.t2t: momscript-classes.h momscript-classes.cpp gendoc.py + $(PYTHON) $(srcdir)/gendoc.py $(srcdir)/momscript-classes.h $(srcdir)/momscript-classes.cpp > $(srcdir)/momscript.t2t.tmp && \ + mv $(srcdir)/momscript.t2t.tmp $(srcdir)/momscript.t2t diff --git a/plugins/script/gendoc.py b/plugins/script/gendoc.py new file mode 100644 index 00000000..86d16ad2 --- /dev/null +++ b/plugins/script/gendoc.py @@ -0,0 +1,14 @@ +import os +import sys +import re + +lines = [] +re_doc = re.compile('^\s*///(\s+(.*))?$') + +for f in sys.argv[1:]: + for line in open(f): + m = re_doc.search(line) + if m: + lines.append(m.group(2) or '') + +print '\n'.join(lines) diff --git a/plugins/script/momscript-classes.cpp b/plugins/script/momscript-classes.cpp index 7ba38e9b..fcc1bad3 100644 --- a/plugins/script/momscript-classes.cpp +++ b/plugins/script/momscript-classes.cpp @@ -124,34 +124,35 @@ static void get_iter_pair(const Variant &val, GtkTextBuffer *buf, GtkTextIter *i // Application // -Variant Application::get_editor() +Variant Application::editor(const VariantArray &args) { + check_no_args(args); return HObject(Editor::get_instance()); } -Variant Application::get_active_window() +Variant Application::active_window(const VariantArray &args) { - return Editor::get_instance().get_active_window(); + return Editor::get_instance().active_window(args); } -void Application::set_active_window(const Variant &val) +Variant Application::set_active_window(const VariantArray &args) { - Editor::get_instance().set_active_window(val); + return Editor::get_instance().set_active_window(args); } -Variant Application::get_active_document() +Variant Application::active_document(const VariantArray &args) { - return Editor::get_instance().get_active_document(); + return Editor::get_instance().active_document(args); } -Variant Application::get_active_view() +Variant Application::active_view(const VariantArray &args) { - return Editor::get_instance().get_active_view(); + return Editor::get_instance().active_view(args); } -Variant Application::get_windows() +Variant Application::windows(const VariantArray &args) { - return Editor::get_instance().get_windows(); + return Editor::get_instance().windows(args); } Variant Application::quit(const VariantArray &args) @@ -167,105 +168,129 @@ Variant Application::quit(const VariantArray &args) // Editor // -Variant Editor::get_active_document() +Variant Editor::active_document(const VariantArray &args) { + check_no_args(args); return HObject(Document::wrap(moo_editor_get_active_doc(moo_editor_instance()))); } -void Editor::set_active_document(const Variant &val) +Variant Editor::set_active_document(const VariantArray &args) { - moo::SharedPtr doc = get_object(val); + check_1_arg(args); + moo::SharedPtr doc = get_object(args[0]); moo_editor_set_active_doc(moo_editor_instance(), doc->gobj()); + return Variant(); } -Variant Editor::get_active_window() +Variant Editor::active_window(const VariantArray &args) { + check_no_args(args); return HObject(DocumentWindow::wrap(moo_editor_get_active_window(moo_editor_instance()))); } -void Editor::set_active_window(const Variant &val) +Variant Editor::set_active_window(const VariantArray &args) { - moo::SharedPtr window = get_object(val); + check_1_arg(args); + moo::SharedPtr window = get_object(args[0]); moo_editor_set_active_window(moo_editor_instance(), window->gobj()); + return Variant(); } -Variant Editor::get_active_view() +Variant Editor::active_view(const VariantArray &args) { + check_no_args(args); return HObject(DocumentView::wrap(moo_editor_get_active_doc(moo_editor_instance()))); } -void Editor::set_active_view(const Variant &val) +Variant Editor::set_active_view(const VariantArray &args) { - moo::SharedPtr view = get_object(val); + check_1_arg(args); + moo::SharedPtr view = get_object(args[0]); moo_editor_set_active_doc(moo_editor_instance(), view->gobj()); - g_print("Editor::set_active_view\n"); + return Variant(); } -Variant Editor::get_documents() +Variant Editor::documents(const VariantArray &args) { + check_no_args(args); GSList *docs = moo_editor_list_docs(moo_editor_instance()); return wrap_gslist(docs); } -Variant Editor::get_views() +Variant Editor::views(const VariantArray &args) { + check_no_args(args); GSList *docs = moo_editor_list_docs(moo_editor_instance()); return wrap_gslist(docs); } -Variant Editor::get_windows() +Variant Editor::windows(const VariantArray &args) { + check_no_args(args); GSList *windows = moo_editor_list_windows(moo_editor_instance()); return wrap_gslist(windows); } +// METHOD(get_document_by_path); +// METHOD(get_document_by_uri); + /////////////////////////////////////////////////////////////////////////////// // // DocumentWindow // -Variant DocumentWindow::get_editor() +Variant DocumentWindow::editor(const VariantArray &args) { + check_no_args(args); return HObject(Editor::get_instance()); } -Variant DocumentWindow::get_active_view() +Variant DocumentWindow::active_view(const VariantArray &args) { + check_no_args(args); return HObject(DocumentView::wrap(moo_edit_window_get_active_doc(gobj()))); } -void DocumentWindow::set_active_view(const Variant &val) +Variant DocumentWindow::set_active_view(const VariantArray &args) { - moo::SharedPtr view = get_object(val); + check_1_arg(args); + moo::SharedPtr view = get_object(args[0]); moo_edit_window_set_active_doc(gobj(), view->gobj()); + return Variant(); } -Variant DocumentWindow::get_active_document() +Variant DocumentWindow::active_document(const VariantArray &args) { + check_no_args(args); return HObject(Document::wrap(moo_edit_window_get_active_doc(gobj()))); } -void DocumentWindow::set_active_document(const Variant &val) +Variant DocumentWindow::set_active_document(const VariantArray &args) { - moo::SharedPtr doc = get_object(val); + check_1_arg(args); + moo::SharedPtr doc = get_object(args[0]); moo_edit_window_set_active_doc(gobj(), doc->gobj()); + return Variant(); } -Variant DocumentWindow::get_views() +Variant DocumentWindow::views(const VariantArray &args) { + check_no_args(args); GSList *docs = moo_edit_window_list_docs(gobj()); return wrap_gslist(docs); } -Variant DocumentWindow::get_documents() +Variant DocumentWindow::documents(const VariantArray &args) { + check_no_args(args); GSList *docs = moo_edit_window_list_docs(gobj()); return wrap_gslist(docs); } -Variant DocumentWindow::get_active() +Variant DocumentWindow::is_active(const VariantArray &args) { + check_no_args(args); return gobj() == moo_editor_get_active_window(moo_editor_instance()); } @@ -282,50 +307,61 @@ Variant DocumentWindow::set_active(const VariantArray &args) // DocumentView // -Variant DocumentView::get_document() +Variant DocumentView::document(const VariantArray &args) { + check_no_args(args); return HObject(Document::wrap(gobj())); } -Variant DocumentView::get_window() +Variant DocumentView::window(const VariantArray &args) { + check_no_args(args); return HObject(DocumentWindow::wrap(moo_edit_get_window(gobj()))); } -Variant DocumentView::get_line_wrap_mode() +Variant DocumentView::line_wrap_mode(const VariantArray &args) { + check_no_args(args); GtkWrapMode mode; g_object_get(gobj(), "wrap-mode", &mode, (char*) NULL); return mode != GTK_WRAP_NONE; } -void DocumentView::set_line_wrap_mode(const Variant &val) +Variant DocumentView::set_line_wrap_mode(const VariantArray &args) { - moo_edit_ui_set_line_wrap_mode(gobj(), get_bool(val)); + check_1_arg(args); + moo_edit_ui_set_line_wrap_mode(gobj(), get_bool(args[0])); + return Variant(); } -Variant DocumentView::get_overwrite_mode() +Variant DocumentView::overwrite_mode(const VariantArray &args) { + check_no_args(args); gboolean overwrite; g_object_get(gobj(), "overwrite", &overwrite, (char*) NULL); return bool(overwrite); } -void DocumentView::set_overwrite_mode(const Variant &val) +Variant DocumentView::set_overwrite_mode(const VariantArray &args) { - g_object_set(gobj(), "overwrite", gboolean(get_bool(val)), (char*) NULL); + check_1_arg(args); + g_object_set(gobj(), "overwrite", gboolean(get_bool(args[0])), (char*) NULL); + return Variant(); } -Variant DocumentView::get_show_line_numbers() +Variant DocumentView::show_line_numbers(const VariantArray &args) { + check_no_args(args); gboolean show; g_object_get(gobj(), "show-line-numbers", &show, (char*) NULL); return bool(show); } -void DocumentView::set_show_line_numbers(const Variant &val) +Variant DocumentView::set_show_line_numbers(const VariantArray &args) { - moo_edit_ui_set_show_line_numbers(gobj(), get_bool(val)); + check_1_arg(args); + moo_edit_ui_set_show_line_numbers(gobj(), get_bool(args[0])); + return Variant(); } @@ -334,42 +370,97 @@ void DocumentView::set_show_line_numbers(const Variant &val) // Document // -Variant Document::get_active_view() +Variant Document::active_view(const VariantArray &args) { + check_no_args(args); return HObject(DocumentView::wrap(gobj())); } -Variant Document::get_views() +Variant Document::views(const VariantArray &args) { + check_no_args(args); VariantArray views; views.append(HObject(DocumentView::wrap(gobj()))); return views; } -Variant Document::get_filename() +Variant Document::filename(const VariantArray &args) { + check_no_args(args); char *filename = moo_edit_get_utf8_filename(gobj()); return filename ? String::take_utf8(filename) : String::Null(); } -Variant Document::get_uri() +Variant Document::uri(const VariantArray &args) { + check_no_args(args); char *uri = moo_edit_get_uri(gobj()); return uri ? String::take_utf8(uri) : String::Null(); } -Variant Document::get_basename() +Variant Document::basename(const VariantArray &args) { + check_no_args(args); return String(moo_edit_get_display_basename(gobj())); } -Variant Document::get_can_undo() +// Variant Document::reload(const VariantArray &args) +// { +// VariantArray editor_args; +// editor_args.append(HObject(*this)); +// editor_args.append(args); +// return Editor::get_instance().reload(editor_args); +// } +// +// Variant Document::save(const VariantArray &args) +// { +// VariantArray editor_args; +// editor_args.append(HObject(*this)); +// editor_args.append(args); +// return Editor::get_instance().save(editor_args); +// } +// +// Variant Document::save_as(const VariantArray &args) +// { +// VariantArray editor_args; +// editor_args.append(HObject(*this)); +// editor_args.append(args); +// return Editor::get_instance().save_as(editor_args); +// } +// +// Variant Document::save_as_uri(const VariantArray &args) +// { +// VariantArray editor_args; +// editor_args.append(HObject(*this)); +// editor_args.append(args); +// return Editor::get_instance().save_as_uri(editor_args); +// } + +// Variant Document::encoding(const VariantArray &args) +// { +// } +// +// Variant Document::set_encoding(const VariantArray &args) +// { +// } +// +// Variant Document::line_endings(const VariantArray &args) +// { +// } +// +// Variant Document::set_line_endings(const VariantArray &args) +// { +// } + +Variant Document::can_undo(const VariantArray &args) { + check_no_args(args); return moo_text_view_can_undo(MOO_TEXT_VIEW(gobj())); } -Variant Document::get_can_redo() +Variant Document::can_redo(const VariantArray &args) { + check_no_args(args); return moo_text_view_can_redo(MOO_TEXT_VIEW(gobj())); } @@ -401,42 +492,49 @@ Variant Document::end_not_undoable_action(const VariantArray &args) return Variant(); } -Variant Document::get_start() +Variant Document::start_pos(const VariantArray &args) { + check_no_args(args); return Index(0); } -Variant Document::get_end() +Variant Document::end_pos(const VariantArray &args) { + check_no_args(args); return Index(gtk_text_buffer_get_char_count(buffer())); } -Variant Document::get_cursor() +Variant Document::cursor_pos(const VariantArray &args) { + check_no_args(args); GtkTextBuffer *buf = buffer(); GtkTextIter iter; gtk_text_buffer_get_iter_at_mark(buf, &iter, gtk_text_buffer_get_insert(buf)); return Index(gtk_text_iter_get_offset(&iter)); } -void Document::set_cursor(const Variant &value) +Variant Document::set_cursor_pos(const VariantArray &args) { + check_1_arg(args); GtkTextBuffer *buf = buffer(); GtkTextIter iter; - get_iter(value, buf, &iter); + get_iter(args[0], buf, &iter); gtk_text_buffer_place_cursor(buf, &iter); + return Variant(); } -Variant Document::get_selection_bound() +Variant Document::selection_bound(const VariantArray &args) { + check_no_args(args); GtkTextBuffer *buf = buffer(); GtkTextIter iter; gtk_text_buffer_get_iter_at_mark(buf, &iter, gtk_text_buffer_get_selection_bound(buf)); return Index(gtk_text_iter_get_offset(&iter)); } -Variant Document::get_selection() +Variant Document::selection(const VariantArray &args) { + check_no_args(args); GtkTextBuffer *buf = buffer(); GtkTextIter start, end; gtk_text_buffer_get_selection_bounds(buf, &start, &end); @@ -444,29 +542,47 @@ Variant Document::get_selection() Index(gtk_text_iter_get_offset(&end))); } -void Document::set_selection(const Variant &value) +Variant Document::set_selection(const VariantArray &args) { GtkTextBuffer *buf = buffer(); GtkTextIter start, end; - get_iter_pair(value, buf, &start, &end); + + if (args.size() == 1) + { + get_iter_pair(args[0], buf, &start, &end); + } + else if (args.size() == 2) + { + get_iter(args[0], buf, &start); + get_iter(args[1], buf, &end); + } + else + { + Error::raise("exactly one or two arguments expected"); + } + gtk_text_buffer_select_range(buf, &start, &end); + return Variant(); } -Variant Document::get_has_selection() +Variant Document::has_selection(const VariantArray &args) { + check_no_args(args); GtkTextBuffer *buf = buffer(); GtkTextIter start, end; gtk_text_buffer_get_selection_bounds(buf, &start, &end); return bool(gtk_text_iter_equal(&start, &end)); } -Variant Document::get_char_count() +Variant Document::char_count(const VariantArray &args) { + check_no_args(args); return gtk_text_buffer_get_char_count(buffer()); } -Variant Document::get_line_count() +Variant Document::line_count(const VariantArray &args) { + check_no_args(args); return gtk_text_buffer_get_line_count(buffer()); } @@ -748,8 +864,9 @@ Variant Document::select_all(const VariantArray &args) return Variant(); } -Variant Document::get_selected_text() +Variant Document::selected_text(const VariantArray &args) { + check_no_args(args); GtkTextBuffer *buf = buffer(); GtkTextIter start, end; gtk_text_buffer_get_selection_bounds(buf, &start, &end); @@ -764,8 +881,9 @@ static void get_selected_lines_bounds(GtkTextBuffer *buf, GtkTextIter *start, Gt gtk_text_iter_set_line_offset(start, 0); } -Variant Document::get_selected_lines() +Variant Document::selected_lines(const VariantArray &args) { + check_no_args(args); GtkTextIter start, end; GtkTextBuffer *buf = buffer(); get_selected_lines_bounds(buf, &start, &end); diff --git a/plugins/script/momscript-classes.h b/plugins/script/momscript-classes.h index 0a2185ac..65ec1f74 100644 --- a/plugins/script/momscript-classes.h +++ b/plugins/script/momscript-classes.h @@ -68,12 +68,13 @@ private: \ SINGLETON_CLASS(Application) { public: - PROPERTY(editor, read); - PROPERTY(active_window, read-write); - PROPERTY(windows, read); + METHOD(editor); + METHOD(active_view); + METHOD(active_document); - PROPERTY(active_view, read); - PROPERTY(active_document, read); + METHOD(active_window); + METHOD(set_active_window); + METHOD(windows); METHOD(quit); @@ -81,17 +82,68 @@ private: MOM_SINGLETON_DECL(Application) }; +/////////////////////////////////////////////////////////////////////////////// +/// +/// ==== Editor ====[mom-script-editor] +/// SINGLETON_CLASS(Editor) { public: - PROPERTY(active_document, read-write); - PROPERTY(active_window, read-write); - PROPERTY(active_view, read-write); - PROPERTY(documents, read); - PROPERTY(views, read); - PROPERTY(windows, read); + /// - ``Editor.active_document()``: returns current active document or null + /// if there are no open documents + METHOD(active_document); + /// - ``Editor.set_active_document(doc)``: makes ``doc`` active + METHOD(set_active_document); + /// - ``Editor.active_window()``: returns current active window + METHOD(active_window); + /// - ``Editor.set_active_window(window)``: makes ``window`` active + METHOD(set_active_window); + /// - ``Editor.active_view()``: returns current active document view + METHOD(active_view); + /// - ``Editor.set_active_view(view)``: makes ``view`` active + METHOD(set_active_view); -// METHOD(open); + /// - ``Editor.documents()``: returns list of all open documents + METHOD(documents); + /// - ``Editor.documents()``: returns list of all open document views + METHOD(views); + /// - ``Editor.documents()``: returns list of all document windows + METHOD(windows); + +// /// - ``Editor.get_document_by_path(path)``: returns document with path +// /// ``path`` or null. +// METHOD(get_document_by_path); +// /// - ``Editor.get_document_by_uri(path)``: returns document with uri +// /// ``uri`` or null. +// METHOD(get_document_by_uri); +// +// /// - ``Editor.open_files(files, window=null)``: open files. If ``window`` is +// /// given then open files in that window, otherwise in an existing window. +// METHOD(open_files); +// /// - ``Editor.open_files(uris, window=null)``: open files. If ``window`` is +// /// given then open files in that window, otherwise in an existing window. +// METHOD(open_uris); +// /// - ``Editor.open_file(file, encoding=null, window=null)``: open file. +// /// If ``encoding`` is null or "auto" then pick character encoding automatically, +// /// otherwise use ``encoding``. +// /// If ``window`` is given then open files in that window, otherwise in an existing window. +// METHOD(open_file); +// /// - ``Editor.open_uri(uri, encoding=null, window=null)``: open file. +// /// If ``encoding`` is null or "auto" then pick character encoding automatically, +// /// otherwise use ``encoding``. +// /// If ``window`` is given then open files in that window, otherwise in an existing window. +// METHOD(open_uri); +// /// - ``Editor.reload(doc)``: reload document. +// METHOD(reload); +// /// - ``Editor.save(doc)``: save document. +// METHOD(save); +// /// - ``Editor.save_as(doc, new_filename=null)``: save document as ``new_filename``. +// /// If ``new_filename`` is not given then first ask user for new filename. +// METHOD(save_as); +// /// - ``Editor.save_as_uri(doc, new_uri=null)``: save document as ``new_uri``. +// /// If ``new_uri`` is not given then first ask user for new filename. +// METHOD(save_as_uri); +// /// ``Editor.close(doc)``: close document. // METHOD(close); private: @@ -169,13 +221,15 @@ protected: \ GOBJECT_CLASS(DocumentWindow, MooEditWindow) { public: - PROPERTY(editor, read); - PROPERTY(active_view, read-write); - PROPERTY(active_document, read-write); - PROPERTY(views, read); - PROPERTY(documents, read); + METHOD(editor); + METHOD(active_view); + METHOD(set_active_view); + METHOD(active_document); + METHOD(set_active_document); + METHOD(views); + METHOD(documents); - PROPERTY(active, read); + METHOD(is_active); METHOD(set_active); private: @@ -185,12 +239,15 @@ private: GOBJECT_CLASS(DocumentView, MooEdit) { public: - PROPERTY(document, read); - PROPERTY(window, read); + METHOD(document); + METHOD(window); - PROPERTY(line_wrap_mode, read-write); - PROPERTY(overwrite_mode, read-write); - PROPERTY(show_line_numbers, read-write); + METHOD(line_wrap_mode); + METHOD(set_line_wrap_mode); + METHOD(overwrite_mode); + METHOD(set_overwrite_mode); + METHOD(show_line_numbers); + METHOD(set_show_line_numbers); private: MOM_GOBJECT_DECL(DocumentView, MooEdit) @@ -199,33 +256,41 @@ private: GOBJECT_CLASS(Document, MooEdit) { public: - PROPERTY(views, read); - PROPERTY(active_view, read); + METHOD(views); + METHOD(active_view); - PROPERTY(filename, read); - PROPERTY(uri, read); - PROPERTY(basename, read); + METHOD(filename); + METHOD(uri); + METHOD(basename); + +// METHOD(encoding); +// METHOD(set_encoding); +// METHOD(line_endings); +// METHOD(set_line_endings); // METHOD(reload); // METHOD(save); // METHOD(save_as); +// METHOD(save_as_uri); - PROPERTY(can_undo, read); - PROPERTY(can_redo, read); + METHOD(can_undo); + METHOD(can_redo); METHOD(undo); METHOD(redo); METHOD(begin_not_undoable_action); METHOD(end_not_undoable_action); - PROPERTY(start, read); - PROPERTY(end, read); - PROPERTY(cursor, read-write); - PROPERTY(selection, read-write); - PROPERTY(selection_bound, read); - PROPERTY(has_selection, read); + METHOD(start_pos); + METHOD(end_pos); + METHOD(cursor_pos); + METHOD(set_cursor_pos); + METHOD(selection); + METHOD(set_selection); + METHOD(selection_bound); + METHOD(has_selection); - PROPERTY(char_count, read); - PROPERTY(line_count, read); + METHOD(char_count); + METHOD(line_count); METHOD(line_at_pos); METHOD(pos_at_line); @@ -248,8 +313,8 @@ public: METHOD(select_lines_at_pos); METHOD(select_all); - PROPERTY(selected_text, read); - PROPERTY(selected_lines, read); + METHOD(selected_text); + METHOD(selected_lines); METHOD(delete_selected_text); METHOD(delete_selected_lines); METHOD(replace_selected_text); diff --git a/plugins/script/momscript-lua.cpp b/plugins/script/momscript-lua.cpp index c0e4f7d8..526cc091 100644 --- a/plugins/script/momscript-lua.cpp +++ b/plugins/script/momscript-lua.cpp @@ -2,6 +2,8 @@ namespace mom { +static void push_object(lua_State *L, const HObject &h); + static gpointer data_cookie; static gpointer object_cookie; @@ -62,6 +64,22 @@ static MomLuaData *get_data(lua_State *L) return data; } +static HObject get_arg_if_object(lua_State *L, int narg) +{ + if (!lua_istable(L, narg)) + return HObject(); + + int id = 0; + + lua_pushlightuserdata(L, &object_cookie); + lua_rawget(L, narg); + if (!lua_isnil(L, -1)) + id = luaL_checkint(L, -1); + lua_pop(L, 1); + + return HObject(id); +} + static HObject get_arg_object(lua_State *L, int narg) { if (!lua_istable(L, narg)) @@ -185,14 +203,27 @@ static void push_variant(lua_State *L, const Variant &v); static int cfunc_call_named_method(lua_State *L) { MomLuaData *data = get_data(L); - HObject h = get_arg_object(L, 1); const char *meth = get_arg_string(L, lua_upvalueindex(1)); + + // Allow both obj.method(arg) and obj:method(arg) syntaxes. + // We store the object as upvalue so it's always available and + // we only need to check whether the first function argument + // is the same object or not. (This does mean a method can't + // take a first argument equal to the target object) + + HObject self = get_arg_object(L, lua_upvalueindex(2)); + HObject harg = get_arg_if_object(L, 1); + + int first_arg = 2; + if (harg.id() != self.id()) + first_arg = 1; + VariantArray args; - for (int i = 2; i <= lua_gettop(L); ++i) + for (int i = first_arg; i <= lua_gettop(L); ++i) args.append(get_arg_variant(L, i)); Variant v; - Result r = data->script->call_method(h, meth, args, v); + Result r = data->script->call_method(self, meth, args, v); check_result(L, r); if (v.vt() != VtVoid) @@ -210,20 +241,21 @@ static int object__index(lua_State *L) { MomLuaData *data = get_data(L); - HObject h = get_arg_object(L, 1); + HObject self = get_arg_object(L, 1); const char *field = get_arg_string(L, 2); - switch (data->script->lookup_field(h, field)) + switch (data->script->lookup_field(self, field)) { case FieldMethod: lua_pushstring(L, field); - lua_pushcclosure(L, cfunc_call_named_method, 1); + push_object(L, self); + lua_pushcclosure(L, cfunc_call_named_method, 2); return 1; case FieldProperty: { Variant v; - Result r = data->script->get_property(h, field, v); + Result r = data->script->get_property(self, field, v); check_result(L, r); push_variant(L, v); return 1; diff --git a/plugins/script/momscript.t2t b/plugins/script/momscript.t2t new file mode 100644 index 00000000..c05a398b --- /dev/null +++ b/plugins/script/momscript.t2t @@ -0,0 +1,16 @@ + +==== Editor ====[mom-script-editor] + +- ``Editor.active_document()``: returns current active document or null +if there are no open documents +- ``Editor.set_active_document(doc)``: makes ``doc`` active +- ``Editor.active_window()``: returns current active window +- ``Editor.set_active_window(window)``: makes ``window`` active +- ``Editor.active_view()``: returns current active document view +- ``Editor.set_active_view(view)``: makes ``view`` active +- ``Editor.documents()``: returns list of all open documents +- ``Editor.documents()``: returns list of all open document views +- ``Editor.documents()``: returns list of all document windows +- ``Editor.get_document(name)``: returns document with name ``name`` or +null. ``name`` is interpreted as full file path, as file URI, as file +basename (file path minus directory path), in that order.