Some more scripting stuff

This commit is contained in:
Yevgen Muntyan 2010-10-25 00:05:49 -07:00
parent bc582fae00
commit a8f5ee4adc
24 changed files with 297 additions and 287 deletions

View File

@ -65,12 +65,6 @@ show debug output in a log window. This option is only useful on Windows.
enable debug output for //DOMAINS// (if **medit** was compiled with
--enable-debug option).
: **--exec** //STRING//
execute python code in //STRING// in an existing instance.
: **--exec-file** //FILE//
execute python file //FILE// in an existing instance.
: **--geometry** //WIDTHxHEIGHT//
: **--geometry** //WIDTHxHEIGHT+X+Y//
default window size and position.

View File

@ -1,116 +0,0 @@
.TH "MEDIT" 1 "September 2010" ""
.SH NAME
.P
medit \- text editor
.SH SYNOPSIS
.P
\fBmedit\fR [\fIOPTION\fR]... [\fIFILES\fR]
.SH DESCRIPTION
.P
\fBmedit\fR is a text editor.
.SH OPTIONS
.TP
\fB\-n\fR, \fB\-\-new\-app\fR
run new instance of \fBmedit\fR. By default \fBmedit\fR opens \fIFILES\fR
(or creates a new document if none are given) in an existing instance
of application
.TP
\fB\-s\fR, \fB\-\-use\-session\fR[=\fIyes|no\fR]
load and save session. By default \fBmedit\fR does it when \fB\-n\fR is not used.
If this option is not given on command line then medit uses the corresponding
preferences setting.
.TP
\fB\-\-pid\fR \fIPID\fR
use existing instance with process id \fIPID\fR.
.TP
\fB\-\-app\-name\fR \fINAME\fR
use instance name \fINAME\fR. If an instance with this name is already running,
then it will send files given on the command line to that instance and exit.
.TP
\fB\-e\fR, \fB\-\-encoding\fR \fIENCODING\fR
use provided character encoding to open the file
.TP
\fB\-l\fR, \fB\-\-line\fR \fILINE\fR
open file and position cursor on line \fILINE\fR. Alternatively
line number may be specified with filename, e.g.
medit foo.txt:12
.TP
\fB\-r\fR, \fB\-\-reload\fR
automatically reload opened file if it was modified on disk by another program.
.TP
\fB\-w\fR, \fB\-\-new\-window\fR
open file in a new window.
.TP
\fB\-t\fR, \fB\-\-new\-tab\fR
open file in a new tab.
.TP
\fB\-\-log\-file\fR \fIFILE\fR
write debug output into \fIFILE\fR. This option is only useful on Windows.
.TP
\fB\-\-log\-window\fR
show debug output in a log window. This option is only useful on Windows.
.TP
\fB\-\-debug\fR \fIDOMAINS\fR
enable debug output for \fIDOMAINS\fR (if \fBmedit\fR was compiled with
\-\-enable\-debug option).
.TP
\fB\-\-exec\fR \fISTRING\fR
execute python code in \fISTRING\fR in an existing instance.
.TP
\fB\-\-exec\-file\fR \fIFILE\fR
execute python file \fIFILE\fR in an existing instance.
.TP
\fB\-\-geometry\fR \fIWIDTHxHEIGHT\fR
.TP
\fB\-\-geometry\fR \fIWIDTHxHEIGHT+X+Y\fR
default window size and position.
.TP
\fB\-h\fR, \fB\-\-help\fR
show summary of options.
.TP
\fB\-v\fR, \fB\-\-version\fR
show program version.
.TP
\fIFILES\fR
list of files to open. Filenames may include line numbers after colon,
e.g. /tmp/file.txt:200. Trailing colon is ignored.
.SH ENVIRONMENT VARIABLES
.TP
MEDIT_PID
if set, it is used as \-\-pid argument. When medit spawns a process (e.g. a DVI viewer) it sets
MEDIT_PID to its own process id, so the child process may in turn simply use 'medit filename'
to open a file (e.g. for inverse DVI search).
.SH CONTACT
.P
http://mooedit.sourceforge.net/contact.html
.SH AUTHOR
.P
Written and maintained by Yevgen Muntyan <emuntyan@sourceforge.net>
.\" man code generated by txt2tags 2.5 (http://txt2tags.sf.net)

View File

@ -7,6 +7,16 @@ require("_moo_utils")
app = medit.get_app_obj()
editor = app.editor()
local __docs_to_cleanup = {}
local function add_doc_to_cleanup(doc)
table.insert(__docs_to_cleanup, doc)
end
local function cleanup()
for i, doc in pairs(__docs_to_cleanup) do
doc.set_modified(false)
end
end
local function test_active_window()
w1 = editor.active_window()
tassert(w1 ~= nil, 'editor.active_window() ~= nil')
@ -27,6 +37,34 @@ local function test_active_window()
tassert(w2 == editor.active_window(), 'w2 == editor.active_window()')
end
test_active_window()
local function test_selection()
doc = editor.new_document()
add_doc_to_cleanup(doc)
tassert(doc.text() == '')
tassert(doc.start_pos() == 1)
tassert(doc.end_pos() == 1)
tassert(doc.text(1, 1) == '')
doc.insert_text('a')
doc.insert_text(1, 'b')
tassert(doc.text() == 'ba')
tassert(doc.start_pos() == 1)
tassert(doc.end_pos() == 3)
tassert(doc.text(1, 2) == 'b')
text = [[abcdefg
abcdefghij
1234567890
]]
doc.replace_text(doc.start_pos(), doc.end_pos(), text)
tassert(doc.start_pos() == 1)
tassert(doc.end_pos() == #text + 1)
doc.select_text(2, 3)
tassert(doc.selected_text() == 'b')
doc.select_text({3, 4})
tassert(doc.selected_text() == 'c')
doc.select_lines(1)
tassert(doc.selected_text() == 'abcdefg\n')
end
-- print(#editor.views())
-- test_active_window()
test_selection()
cleanup()

View File

@ -58,7 +58,10 @@ static struct MeditOpts {
const char *debug;
gboolean ut;
gboolean ut_list;
char *ut_dir;
char **ut_tests;
char **run_script;
char **send_script;
} medit_opts = { -1, -1 };
#include "parse.h"
@ -148,18 +151,16 @@ static GOptionEntry medit_options[] = {
/* "ENCODING" part in --encoding=ENCODING */ N_("ENCODING") },
{ "reload", 'r', 0, G_OPTION_ARG_NONE, &medit_opts.reload,
/* help message for command line option --reload */ N_("Automatically reload file if it was modified on disk"), NULL },
{ "run-script", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY, (gpointer) &medit_opts.run_script,
"Run SCRIPT", "SCRIPT" },
{ "send-script", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY, (gpointer) &medit_opts.send_script,
"Send SCRIPT to existing instance", "SCRIPT" },
{ "log-window", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &medit_opts.log_window,
"Show debug output", NULL },
{ "log-file", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, (gpointer) &medit_opts.log_file,
"Write debug output to FILE", "FILE" },
{ "debug", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, (gpointer) &medit_opts.debug,
"Run in debug mode", NULL },
{ "exec", 0, 0, G_OPTION_ARG_STRING, (gpointer) &medit_opts.exec_string,
/* help message for command line option --exec CODE */ N_("Execute python code in an existing instance"),
/* "CODE" part in --exec CODE */ N_("CODE") },
{ "exec-file", 0, 0, G_OPTION_ARG_FILENAME, (gpointer) &medit_opts.exec_file,
/* help message for command line option --exec-file FILE */ N_("Execute python file in an existing instance"),
/* "FILE" part in --exec-file FILE */ N_("FILE") },
{ "geometry", 0, 0, G_OPTION_ARG_STRING, (gpointer) &medit_opts.geometry,
/* help message for command line option --geometry=WIDTHxHEIGHT[+X+Y] */ N_("Default window size and position"),
/* "WIDTHxHEIGHT[+X+Y]" part in --geometry=WIDTHxHEIGHT[+X+Y] */ N_("WIDTHxHEIGHT[+X+Y]") },
@ -167,6 +168,8 @@ static GOptionEntry medit_options[] = {
/* help message for command line option --version */ N_("Show version information and exit"), NULL },
{ "ut", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &medit_opts.ut,
"Run unit tests", NULL },
{ "ut-dir", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &medit_opts.ut_dir,
"Data dir for unit tests", NULL },
{ "ut-list", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &medit_opts.ut_list,
"List unit tests", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &medit_opts.files,
@ -203,14 +206,6 @@ post_parse_func (void)
exit (EXIT_FAILURE);
}
if (medit_opts.exec_string && medit_opts.exec_file)
{
/* error message for wrong commmand line */
g_printerr (_("%s and %s options may not be used simultaneously\n"),
"--exec", "--exec-file");
exit (EXIT_FAILURE);
}
if (medit_opts.debug)
g_setenv ("MOO_DEBUG", medit_opts.debug, FALSE);
@ -532,11 +527,20 @@ static gboolean
unit_test_func (void)
{
MooTestOptions opts = 0;
unit_tests_main (opts, medit_opts.ut_tests);
unit_tests_main (opts, medit_opts.ut_tests, medit_opts.ut_dir);
moo_app_quit (moo_app_get_instance ());
return FALSE;
}
static gboolean
run_script_func (void)
{
char **p;
for (p = medit_opts.run_script; p && *p; ++p)
moo_app_run_script (moo_app_get_instance(), *p);
return FALSE;
}
static int
medit_main (int argc, char *argv[])
{
@ -598,12 +602,15 @@ medit_main (int argc, char *argv[])
if (name && !name[0])
name = NULL;
if (medit_opts.exec_string || medit_opts.exec_file)
if (medit_opts.send_script)
{
GString *msg;
msg = g_string_new (medit_opts.exec_string ? "p" : "P");
g_string_append (msg, medit_opts.exec_string ? medit_opts.exec_string : medit_opts.exec_file);
moo_app_send_msg (name, msg->str, msg->len + 1);
char **p;
for (p = medit_opts.send_script; *p; ++p)
{
GString *msg = g_string_new ("e");
g_string_append (msg, *p);
moo_app_send_msg (name, msg->str, msg->len + 1);
}
notify_startup_complete ();
exit (0);
}
@ -682,7 +689,9 @@ medit_main (int argc, char *argv[])
g_option_context_free (ctx);
if (medit_opts.ut)
g_timeout_add (10, (GSourceFunc) unit_test_func, NULL);
_moo_timeout_add (10, (GSourceFunc) unit_test_func, NULL);
if (medit_opts.run_script)
_moo_timeout_add (10, (GSourceFunc) run_script_func, NULL);
retval = moo_app_run (app);
gdk_threads_leave ();

View File

@ -25,11 +25,12 @@ add_tests (void)
}
static int
unit_tests_main (MooTestOptions opts, char **tests)
unit_tests_main (MooTestOptions opts, char **tests, const char *data_dir_arg)
{
const char *data_dir;
const char *data_dir = MOO_UNIT_TEST_DATA_DIR;
data_dir = MOO_UNIT_TEST_DATA_DIR;
if (data_dir_arg)
data_dir = data_dir_arg;
add_tests ();
moo_test_run_tests (tests, data_dir, opts);
@ -51,5 +52,5 @@ unit_tests_main (MooTestOptions opts, char **tests)
static void
list_unit_tests (void)
{
unit_tests_main (MOO_TEST_LIST_ONLY, NULL);
unit_tests_main (MOO_TEST_LIST_ONLY, NULL, NULL);
}

View File

@ -22,27 +22,18 @@ G_BEGIN_DECLS
typedef enum
{
CMD_PYTHON_SCRIPT = 1,
CMD_PYTHON_FILE,
CMD_LUA_SCRIPT,
CMD_LUA_FILE,
CMD_SCRIPT = 1,
CMD_OPEN_FILES,
CMD_LAST
} MooAppCmdCode;
/* I is taken by the IPC thing */
#define CMD_PYTHON_SCRIPT_S "p"
#define CMD_PYTHON_FILE_S "P"
#define CMD_LUA_SCRIPT_S "l"
#define CMD_LUA_FILE_S "L"
#define CMD_SCRIPT_S "e"
#define CMD_OPEN_FILES_S "F"
static const char *moo_app_cmd_chars =
"\0"
CMD_PYTHON_SCRIPT_S
CMD_PYTHON_FILE_S
CMD_LUA_SCRIPT_S
CMD_LUA_FILE_S
CMD_SCRIPT_S
CMD_OPEN_FILES_S
;

View File

@ -24,6 +24,7 @@
#include "mooapp-accels.h"
#include "mooapp-info.h"
#include "mooappabout.h"
#include "moolua/moolua.h"
#include "mooedit/mooeditprefs.h"
#include "mooedit/mooeditor.h"
#include "mooedit/mooplugin.h"
@ -475,45 +476,63 @@ moo_app_get_instance (void)
}
static void
run_python_file (MooApp *app,
const char *filename)
{
FILE *file;
MooPyObject *res;
#define SCRIPT_PREFIX_LUA "lua-script:"
#define SCRIPT_PREFIX_LUA_FILE "lua-file:"
void
moo_app_run_script (MooApp *app,
const char *script)
{
g_return_if_fail (MOO_IS_APP (app));
g_return_if_fail (filename != NULL);
g_return_if_fail (moo_python_running ());
g_return_if_fail (script != NULL);
file = _moo_fopen (filename, "rb");
g_return_if_fail (file != NULL);
res = moo_python_run_file (file, filename, NULL, NULL);
fclose (file);
if (res)
moo_Py_DECREF (res);
if (g_str_has_prefix (script, SCRIPT_PREFIX_LUA))
medit_lua_run_string (script + strlen (SCRIPT_PREFIX_LUA));
else if (g_str_has_prefix (script, SCRIPT_PREFIX_LUA_FILE))
medit_lua_run_file (script + strlen (SCRIPT_PREFIX_LUA_FILE));
else
moo_PyErr_Print ();
medit_lua_run_string (script);
}
static void
run_python_script (const char *string)
{
MooPyObject *res;
g_return_if_fail (string != NULL);
g_return_if_fail (moo_python_running ());
res = moo_python_run_simple_string (string);
if (res)
moo_Py_DECREF (res);
else
moo_PyErr_Print ();
}
// static void
// run_python_file (MooApp *app,
// const char *filename)
// {
// FILE *file;
// MooPyObject *res;
//
// g_return_if_fail (MOO_IS_APP (app));
// g_return_if_fail (filename != NULL);
// g_return_if_fail (moo_python_running ());
//
// file = _moo_fopen (filename, "rb");
// g_return_if_fail (file != NULL);
//
// res = moo_python_run_file (file, filename, NULL, NULL);
//
// fclose (file);
//
// if (res)
// moo_Py_DECREF (res);
// else
// moo_PyErr_Print ();
// }
//
// static void
// run_python_script (const char *string)
// {
// MooPyObject *res;
//
// g_return_if_fail (string != NULL);
// g_return_if_fail (moo_python_running ());
//
// res = moo_python_run_simple_string (string);
//
// if (res)
// moo_Py_DECREF (res);
// else
// moo_PyErr_Print ();
// }
MooEditor *
@ -1303,18 +1322,9 @@ moo_app_exec_cmd (MooApp *app,
switch (code)
{
case CMD_PYTHON_SCRIPT:
run_python_script (data);
case CMD_SCRIPT:
moo_app_run_script (app, data);
break;
case CMD_PYTHON_FILE:
run_python_file (app, data);
break;
// case CMD_LUA_SCRIPT:
// run_lua_script (data);
// break;
// case CMD_LUA_FILE:
// run_lua_file (app, data);
// break;
case CMD_OPEN_FILES:
moo_app_cmd_open_files (app, data);

View File

@ -100,6 +100,8 @@ void moo_app_open_files (MooApp *app,
MooAppFileInfo *files,
int n_files,
guint32 stamp);
void moo_app_run_script (MooApp *app,
const char *script);
G_END_DECLS

View File

@ -88,8 +88,12 @@ cfunc_spin_main_loop (lua_State *L)
g_return_val_if_fail (sec >= 0, 0);
GMainLoop *main_loop = g_main_loop_new (NULL, FALSE);
g_timeout_add (sec * 1000, (GSourceFunc) quit_main_loop, main_loop);
_moo_timeout_add (sec * 1000, (GSourceFunc) quit_main_loop, main_loop);
gdk_threads_leave ();
g_main_loop_run (main_loop);
gdk_threads_enter ();
g_main_loop_unref (main_loop);
return 0;
@ -163,7 +167,7 @@ moo_lua_add_user_path (lua_State *L)
lua_State *
medit_lua_new (const char *init, bool enable_callbacks)
medit_lua_new (bool default_init, bool enable_callbacks)
{
lua_State *L = lua_open ();
moo_return_val_if_fail (L != NULL, NULL);
@ -173,7 +177,7 @@ medit_lua_new (const char *init, bool enable_callbacks)
moo_assert (lua_gettop (L) == 0);
if (!mom::lua_setup (L, enable_callbacks))
if (!mom::lua_setup (L, default_init, enable_callbacks))
{
lua_close (L);
return NULL;
@ -181,36 +185,74 @@ medit_lua_new (const char *init, bool enable_callbacks)
moo_assert (lua_gettop (L) == 0);
if (init)
{
if (luaL_loadstring (L, init) != 0)
{
const char *msg = lua_tostring (L, -1);
moo_critical ("%s", msg ? msg : "ERROR");
lua_close (L);
return NULL;
}
return L;
}
if (lua_pcall (L, 0, 0, 0) != 0)
{
const char *msg = lua_tostring (L, -1);
moo_critical ("%s", msg ? msg : "ERROR");
lua_close (L);
return NULL;
}
bool
medit_lua_do_string (lua_State *L, const char *string)
{
moo_return_val_if_fail (L != NULL, FALSE);
moo_return_val_if_fail (string != NULL, FALSE);
if (luaL_dostring (L, string) != 0)
{
const char *msg = lua_tostring (L, -1);
g_critical ("%s: %s", G_STRLOC, msg ? msg : "ERROR");
return false;
}
moo_assert (lua_gettop (L) == 0);
return true;
}
return L;
bool
medit_lua_do_file (lua_State *L, const char *filename)
{
moo_return_val_if_fail (L != NULL, FALSE);
moo_return_val_if_fail (filename != NULL, FALSE);
char *content = NULL;
GError *error = NULL;
if (!g_file_get_contents (filename, &content, NULL, &error))
{
moo_warning ("could not read file '%s': %s", filename, error->message);
g_error_free (error);
return false;
}
gboolean ret = medit_lua_do_string (L, content);
g_free (content);
return ret;
}
void
medit_lua_free (lua_State *L)
{
moo_return_if_fail (L != NULL);
mom::lua_cleanup (L);
lua_close (L);
if (L)
{
mom::lua_cleanup (L);
lua_close (L);
}
}
extern "C" void
medit_lua_run_string (const char *string)
{
moo_return_if_fail (string != NULL);
lua_State *L = medit_lua_new (TRUE, FALSE);
if (L)
medit_lua_do_string (L, string);
medit_lua_free (L);
}
extern "C" void
medit_lua_run_file (const char *filename)
{
moo_return_if_fail (filename != NULL);
lua_State *L = medit_lua_new (TRUE, FALSE);
if (L)
medit_lua_do_file (L, filename);
medit_lua_free (L);
}

View File

@ -16,6 +16,8 @@
#ifndef MOO_LUA_H
#define MOO_LUA_H
#ifdef __cplusplus
#include "lualib.h"
#include "lauxlib.h"
@ -43,8 +45,26 @@ const char *lua_check_utf8string (lua_State *L,
void moo_lua_add_user_path (lua_State *L);
lua_State *medit_lua_new (const char *init = NULL,
bool enable_callbacks = false);
lua_State *medit_lua_new (bool default_init,
bool enable_callbacks);
void medit_lua_free (lua_State *L);
bool medit_lua_do_string (lua_State *L,
const char *string);
bool medit_lua_do_file (lua_State *L,
const char *filename);
#endif /* __cplusplus */
#ifdef __cplusplus
extern "C" {
#endif
void medit_lua_run_string (const char *string);
void medit_lua_run_file (const char *filename);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* MOO_LUA_H */

View File

@ -22,6 +22,12 @@ EXTRA_DIST += \
$(MOO_SCRIPT_PARSER_FILES) \
mooscript/mooscript.xml
EXTRA_DIST += mooscript/lua-default-init.lua
built_moo_sources += lua-default-init.h
lua-default-init.h: mooscript/lua-default-init.lua $(top_srcdir)/tools/xml2h.py
$(AM_V_GEN)$(PYTHON) $(top_srcdir)/tools/xml2h.py $(srcdir)/mooscript/lua-default-init.lua lua-default-init.h.tmp LUA_DEFAULT_INIT \
&& mv lua-default-init.h.tmp lua-default-init.h
if MOO_DEV_MODE
built_moo_sources += \
mooscript/mooscript.stamp

View File

@ -0,0 +1,5 @@
local _g = getfenv(0)
require("moo.builtin")._inject(_g)
local medit = require("medit")
_g.app = medit.get_app_obj()
_g.editor = _g.app.editor()

View File

@ -62,9 +62,13 @@ static String get_string(const Variant &val, bool null_ok = false)
static moo::Vector<String> get_string_list(const Variant &val)
{
if (val.vt() != VtArray)
VariantArray ar;
if (val.vt() == VtArray)
ar = val.value<VtArray>();
else if (val.vt() == VtArgs)
ar = val.value<VtArgs>();
else
Error::raise("list expected");
const VariantArray &ar = val.value<VtArray>();
moo::Vector<String> ret;
for (int i = 0, c = ar.size(); i < c; ++i)
ret.append(get_string(ar[i]));
@ -113,9 +117,13 @@ static void get_iter(const Variant &val, GtkTextBuffer *buf, GtkTextIter *iter)
static void get_pair(const Variant &val, Variant &elm1, Variant &elm2)
{
if (val.vt() != VtArray)
VariantArray ar;
if (val.vt() == VtArray)
ar = val.value<VtArray>();
else if (val.vt() == VtArgs)
ar = val.value<VtArgs>();
else
Error::raise("pair of values expected");
const VariantArray &ar = val.value<VtArray>();
if (ar.size() != 2)
Error::raise("pair of values expected");
elm1 = ar[0];
@ -674,6 +682,20 @@ String Document::basename()
return String(moo_edit_get_display_basename(gobj()));
}
/// @item Document.is_modified()
/// returns whether the document is modified.
bool Document::is_modified()
{
return MOO_EDIT_IS_MODIFIED(gobj());
}
/// @item Document.set_modified(modified)
/// sets modification state of the document.
void Document::set_modified(bool modified)
{
moo_edit_set_modified(gobj(), modified);
}
/// @item Document.encoding()
/// returns character encoding of the document.
String Document::encoding()

View File

@ -1,4 +1,5 @@
#include "mooscript-lua.h"
#include "lua-default-init.h"
namespace mom {
@ -447,7 +448,7 @@ static bool add_raw_api(lua_State *L, bool enable_callbacks)
return true;
}
bool lua_setup(lua_State *L, bool enable_callbacks) throw()
bool lua_setup(lua_State *L, bool default_init, bool enable_callbacks) throw()
{
try
{
@ -466,6 +467,9 @@ bool lua_setup(lua_State *L, bool enable_callbacks) throw()
g_assert (lua_gettop (L) == 0);
if (default_init)
medit_lua_do_string (L, LUA_DEFAULT_INIT);
return true;
}
catch (...)

View File

@ -6,7 +6,7 @@
namespace mom {
bool lua_setup(lua_State *L, bool enable_callbacks) throw();
bool lua_setup(lua_State *L, bool default_init, bool enable_callbacks) throw();
void lua_cleanup(lua_State *L) throw();
} // namespace mom

View File

@ -109,6 +109,9 @@
<method name='uri' retval='string'/>
<method name='basename' retval='string'/>
<method name='is_modified' retval='bool'/>
<method name='set_modified' param-type='bool' param-name='modified'/>
<method name='encoding' retval='string'/>
<method name='set_encoding' param-name='encoding' param-type='string'/>

View File

@ -1,10 +1,4 @@
local _g = getfenv(0)
require("moo.builtin")._inject(_g)
local medit = require("medit")
_g.app = medit.get_app_obj()
_g.editor = _g.app.editor()
local __medit_callbacks = {}

View File

@ -36,40 +36,22 @@ struct MooLuaPlugin {
ModuleList *modules;
};
static bool
load_file (lua_State *L, const char *module_file)
{
char *content = NULL;
GError *error = NULL;
if (!g_file_get_contents (module_file, &content, NULL, &error))
{
moo_warning ("could not read file '%s': %s", module_file, error->message);
g_error_free (error);
return false;
}
bool ret = true;
if (luaL_dostring (L, content) != 0)
{
const char *msg = lua_tostring (L, -1);
g_critical ("%s: %s", G_STRLOC, msg ? msg : "ERROR");
ret = false;
}
g_free (content);
return ret;
}
static MooLuaModule *
moo_lua_module_load (const char *filename)
{
lua_State *L = medit_lua_new (LUA_MODULE_SETUP_CODE);
lua_State *L = medit_lua_new (true, true);
if (!L)
return NULL;
if (!load_file (L, filename))
if (!medit_lua_do_string (L, LUA_MODULE_SETUP_CODE))
{
lua_close (L);
medit_lua_free (L);
return NULL;
}
if (!medit_lua_do_file (L, filename))
{
medit_lua_free (L);
return NULL;
}

View File

@ -1,10 +1,4 @@
local _g = getfenv(0)
require("moo.builtin")._inject(_g)
local medit = require("medit")
_g.app = medit.get_app_obj()
_g.editor = _g.app.editor()
_g.doc = _g.app.active_document()
_g.view = _g.app.active_view()
_g.window = _g.app.active_window()

View File

@ -50,14 +50,20 @@ moo_command_lua_run (MooCommand *cmd_base,
g_return_if_fail (cmd->priv->code != NULL);
L = medit_lua_new (LUA_SETUP_CODE);
L = medit_lua_new (TRUE, FALSE);
g_return_if_fail (L != NULL);
if (!medit_lua_do_string (L, LUA_SETUP_CODE))
{
medit_lua_free (L);
return;
}
if (luaL_loadstring (L, cmd->priv->code) != 0)
{
const char *msg = lua_tostring (L, -1);
g_critical ("%s: %s", G_STRLOC, msg ? msg : "ERROR");
lua_close (L);
medit_lua_free (L);
return;
}

View File

@ -25,4 +25,4 @@ bdist:
bdist-all: bdist-en bdist
clean:
rm -rf $(mgwtargetdir) $(mgwdestdir) $(mgwdestdir)-en
rm -rf $(mgwbuilddir) $(mgwdestdir) $(mgwdestdir)-en

View File

@ -1,5 +1,6 @@
export mgwdir_s=$mgwdir
export mgwdir=`cd $mgwdir && pwd`
export mgwbuildroot=$HOME/projects/gtk-win-build
export mgwconfig=release
case "$1" in
@ -13,10 +14,10 @@ case "$1" in
;;
esac
export mgwdestdir=$mgwdir/bdist-$mgwconfig
export mgwdestdir=$mgwbuildroot/bdist-$mgwconfig
export mgwbuilddir=$mgwdir/$mgwconfig
export mgwbuilddir_s=$mgwdir_s/$mgwconfig
export mgwbuilddir=$mgwbuildroot/$mgwconfig
export mgwbuilddir_s=$mgwbuildroot/$mgwconfig
export mgwsourcedir=$mgwbuilddir/source
export mgwtargetdir=$mgwbuilddir/target
export mgwsourcedir_s=$mgwbuilddir_s/source

View File

@ -2,6 +2,7 @@
_gtkwindir = os.environ['_GTKWINDIR']
_gtkwinjhbuilddir = os.path.join(_gtkwindir, 'jhbuildrc')
_gtkwinbuildroot = os.environ['_GTKWINBUILDROOT']
_gtkwinconfig = os.environ.get('_GTKWINCONFIG')
if _gtkwinconfig is None:
@ -23,10 +24,10 @@ use_lib64 = False
modules = ['medit-gtk-win']
checkoutroot = os.path.join(_gtkwindir, _gtkwinconfig, 'source')
buildroot = os.path.join(_gtkwindir, _gtkwinconfig, 'build')
prefix = os.path.join(_gtkwindir, _gtkwinconfig, 'target')
tarballdir = os.path.join(_gtkwindir, 'tarballs')
checkoutroot = os.path.join(_gtkwinbuildroot, _gtkwinconfig, 'source')
buildroot = os.path.join(_gtkwinbuildroot, _gtkwinconfig, 'build')
prefix = os.path.join(_gtkwinbuildroot, _gtkwinconfig, 'target')
tarballdir = os.path.join(_gtkwinbuildroot, 'tarballs')
os.environ['prefix'] = prefix

View File

@ -9,6 +9,7 @@ fi
export _GTKWINDIR=`cd $mgwdir && pwd`
export _GTKWINCONFIG=$mgwconfig
export _GTKWINBUILDROOT=$mgwbuildroot
# JHBUILD=$mgwdir_s/jhbuild/bin/jhbuild
JHBUILD=jhbuild