Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
magic-lantern
magic-lantern
Commits
3aecd23e4eef
Commit
6fee0b0a
authored
Jun 19, 2016
by
alex@thinkpad
Browse files
Lua: show last script error in menu (to be tested)
--HG-- branch : lua_fix
parent
981090dc32c9
Changes
6
Hide whitespace changes
Inline
Side-by-side
modules/lua/lua.c
View file @
3aecd23e
...
...
@@ -168,6 +168,7 @@ static unsigned int lua_do_cbr(unsigned int ctx, struct script_event_entry * eve
if
(
docall
(
L
,
1
,
1
))
{
fprintf
(
stderr
,
"lua cbr error:
\n
%s
\n
"
,
lua_tostring
(
L
,
-
1
));
lua_save_last_error
(
L
);
result
=
CBR_RET_ERROR
;
give_semaphore
(
sem
);
break
;
...
...
@@ -553,9 +554,9 @@ struct lua_script
char
*
filename
;
char
*
name
;
char
*
description
;
char
*
last_error
;
int
autorun
;
int
state
;
int
error
;
int
load_time
;
int
cant_unload
;
lua_State
*
L
;
...
...
@@ -587,6 +588,27 @@ void lua_set_cant_unload(lua_State * L, int cant_unload, int mask)
fprintf
(
stderr
,
"lua_set_cant_unload: script not found
\n
"
);
}
static
void
lua_clear_last_error
(
struct
lua_script
*
script
)
{
if
(
script
->
last_error
)
{
free
(
script
->
last_error
);
script
->
last_error
=
0
;
}
}
void
lua_save_last_error
(
lua_State
*
L
)
{
for
(
struct
lua_script
*
script
=
lua_scripts
;
script
;
script
=
script
->
next
)
{
if
(
script
->
L
==
L
)
{
lua_clear_last_error
(
script
);
script
->
last_error
=
copy_string
(
lua_tostring
(
L
,
-
1
));
}
}
}
static
int
lua_get_config_flag_path
(
struct
lua_script
*
script
,
char
*
full_path
,
const
char
*
flag
)
{
snprintf
(
full_path
,
MAX_PATH_LEN
,
"%s%s"
,
get_config_dir
(),
script
->
filename
);
...
...
@@ -639,6 +661,7 @@ static void load_script(struct lua_script * script)
script
->
state
=
SCRIPT_STATE_LOADING
;
lua_State
*
L
=
script
->
L
=
load_lua_state
();
script
->
cant_unload
=
0
;
lua_clear_last_error
(
script
);
if
(
!
script
->
sem
)
{
...
...
@@ -665,7 +688,16 @@ static void load_script(struct lua_script * script)
error
=
1
;
}
give_semaphore
(
script
->
sem
->
semaphore
);
if
(
error
)
{
/* save the last error string for this script */
lua_save_last_error
(
L
);
/* disable autorun on error */
set_script_autorun
(
script
,
0
);
}
if
(
script
->
cant_unload
)
{
/* "complex" script that keeps running after load
...
...
@@ -675,8 +707,8 @@ static void load_script(struct lua_script * script)
script
->
menu_entry
->
icon_type
=
IT_BOOL
;
script
->
menu_entry
->
children
[
0
].
shidden
=
1
;
/*
if there was an error, disable autorun, otherwise turn it on
*/
set_script_autorun
(
script
,
!
error
);
/*
enable autorun if there was no error
*/
if
(
!
error
)
set_script_autorun
(
script
,
1
);
}
else
{
...
...
@@ -689,14 +721,6 @@ static void load_script(struct lua_script * script)
script
->
state
=
SCRIPT_STATE_NOT_RUNNING
;
script
->
load_time
=
0
;
}
script
->
error
=
error
;
if
(
error
)
{
/* disable autorun on error */
set_script_autorun
(
script
,
0
);
}
}
else
{
...
...
@@ -735,7 +759,7 @@ static MENU_UPDATE_FUNC(lua_script_menu_update)
bmp_printf
(
fnt
|
FONT_ALIGN_RIGHT
,
680
,
info
->
y
+
2
,
script
->
autorun
?
"AUTORUN"
:
script
->
error
script
->
last_
error
?
"ERROR"
:
script
->
state
==
SCRIPT_STATE_NOT_RUNNING
?
""
:
...
...
@@ -757,9 +781,9 @@ static MENU_UPDATE_FUNC(lua_script_menu_update)
}
if
(
script
->
error
)
if
(
script
->
last_
error
)
{
MENU_SET_WARNING
(
MENU_WARN_NOT_WORKING
,
"
Script Failed"
);
MENU_SET_WARNING
(
MENU_WARN_NOT_WORKING
,
"
%s"
,
script
->
last_error
);
}
}
}
...
...
modules/lua/lua_common.h
View file @
3aecd23e
...
...
@@ -107,6 +107,7 @@ int lua_take_semaphore(lua_State * L, int timeout, struct semaphore ** assoc_sem
int
lua_give_semaphore
(
lua_State
*
L
,
struct
semaphore
**
assoc_semaphore
);
void
lua_set_cant_unload
(
lua_State
*
L
,
int
cant_unload
,
int
mask
);
void
lua_save_last_error
(
lua_State
*
L
);
int
luaCB_next
(
lua_State
*
L
);
int
luaCB_pairs
(
lua_State
*
L
);
...
...
modules/lua/lua_lv.c
View file @
3aecd23e
...
...
@@ -160,6 +160,7 @@ static LVINFO_UPDATE_FUNC(lua_lvinfo_update)
if
(
docall
(
L
,
1
,
1
))
{
fprintf
(
stderr
,
"script error:
\n
%s
\n
"
,
lua_tostring
(
L
,
-
1
));
lua_save_last_error
(
L
);
}
}
lua_pop
(
L
,
1
);
...
...
modules/lua/lua_menu.c
View file @
3aecd23e
...
...
@@ -35,6 +35,7 @@ static void lua_menu_task(lua_State * L)
if
(
docall
(
L
,
arg_count
,
0
))
{
printf
(
"script failed:
\n
%s
\n
"
,
lua_tostring
(
L
,
-
1
));
lua_save_last_error
(
L
);
}
else
{
...
...
@@ -101,6 +102,7 @@ static MENU_SELECT_FUNC(script_menu_select)
if
(
docall
(
L
,
2
,
0
))
{
fprintf
(
stderr
,
"script error:
\n
%s
\n
"
,
lua_tostring
(
L
,
-
1
));
lua_save_last_error
(
L
);
}
give_semaphore
(
sem
);
}
...
...
modules/lua/lua_property.c
View file @
3aecd23e
...
...
@@ -85,6 +85,7 @@ static void lua_prop_task(int unused)
if
(
docall
(
L
,
2
,
0
))
{
fprintf
(
stderr
,
"script prop handler failed:
\n
%s
\n
"
,
lua_tostring
(
L
,
-
1
));
lua_save_last_error
(
L
);
}
}
give_semaphore
(
sem
);
...
...
modules/lua/lua_task.c
View file @
3aecd23e
...
...
@@ -35,6 +35,7 @@ static void lua_run_task(struct lua_task_func * lua_task_func)
if
(
docall
(
L
,
0
,
0
))
{
fprintf
(
stderr
,
"script failed:
\n
%s
\n
"
,
lua_tostring
(
L
,
-
1
));
lua_save_last_error
(
L
);
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment