Commit 036024a8 authored by a1ex's avatar a1ex
Browse files

Lua scripting: always open console on script errors

--HG--
branch : lua
parent 9f8dab3b6aae
......@@ -63,7 +63,7 @@ int lua_take_semaphore(lua_State * L, int timeout, struct semaphore ** assoc_sem
return take_semaphore(current->semaphore, timeout);
}
}
console_printf("error: could not find semaphore for lua state\n");
err_printf("error: could not find semaphore for lua state\n");
return -1;
}
......@@ -78,7 +78,7 @@ int lua_give_semaphore(lua_State * L, struct semaphore ** assoc_semaphore)
return give_semaphore(current->semaphore);
}
}
console_printf("error: could not find semaphore for lua state\n");
err_printf("error: could not find semaphore for lua state\n");
return -1;
}
......@@ -158,7 +158,7 @@ static unsigned int lua_do_cbr(unsigned int ctx, struct script_event_entry * eve
lua_pushinteger(L, ctx);
if(docall(L, 1, 1))
{
console_printf("lua cbr error:\n %s\n", lua_tostring(L, -1));
err_printf("lua cbr error:\n %s\n", lua_tostring(L, -1));
result = CBR_RET_ERROR;
give_semaphore(sem);
break;
......@@ -180,7 +180,7 @@ static unsigned int lua_do_cbr(unsigned int ctx, struct script_event_entry * eve
}
else
{
console_printf("lua semaphore timeout (another task is running this script)\n");
err_printf("lua semaphore timeout (another task is running this script)\n");
}
}
}
......@@ -406,17 +406,17 @@ static void add_script(const char * filename)
{
char full_path[MAX_PATH_LEN];
snprintf(full_path, MAX_PATH_LEN, SCRIPTS_DIR "/%s", filename);
console_printf("Loading script: %s\n", filename);
printf("Loading script: %s\n", filename);
if(luaL_loadfile(L, full_path) || docall(L, 0, LUA_MULTRET))
{
/* error loading script */
console_printf("%s\n", lua_tostring(L, -1));
err_printf("%s\n", lua_tostring(L, -1));
}
give_semaphore(sem);
}
else
{
console_printf("load script failed: could not create semaphore\n");
err_printf("load script failed: could not create semaphore\n");
}
}
......
......@@ -6,8 +6,9 @@
#include <console.h>
#include <string.h>
#define lua_writestringerror(s,p) (console_printf((s), (p)))
#define lua_writestring(s,l) (console_printf("%s",(s)))
#define err_printf(fmt,...) console_show(), printf(fmt, ## __VA_ARGS__)
#define lua_writestringerror(s,p) (err_printf((s), (p)))
#define lua_writestring(s,l) (err_printf("%s",(s)))
#define getc(a) my_getc(a)
#define fopen(a,b) my_fopen(a,b)
#define freopen(a,b,c) my_freopen(a,b,c)
......
......@@ -112,7 +112,7 @@ static LVINFO_UPDATE_FUNC(lua_lvinfo_update)
lua_rawgeti(L, LUA_REGISTRYINDEX, entry->self_ref);
if(docall(L, 1, 1))
{
console_printf("script error:\n %s\n", lua_tostring(L, -1));
err_printf("script error:\n %s\n", lua_tostring(L, -1));
}
}
lua_pop(L,1);
......@@ -121,7 +121,7 @@ static LVINFO_UPDATE_FUNC(lua_lvinfo_update)
}
else
{
console_printf("lua semaphore timeout (another task is running this script)\n");
err_printf("lua semaphore timeout (another task is running this script)\n");
}
}
......@@ -328,4 +328,4 @@ static const luaL_Reg lvlib[] =
{ NULL, NULL }
};
LUA_LIB(lv)
\ No newline at end of file
LUA_LIB(lv)
......@@ -31,20 +31,20 @@ static void lua_menu_task(lua_State * L)
int arg_count = lua_tointegerx(L, -1, &isnum);
if(isnum) lua_pop(L,1);
else arg_count = 0;
console_printf("running script...\n");
printf("running script...\n");
if(docall(L, arg_count, 0))
{
console_printf("script failed:\n %s\n", lua_tostring(L, -1));
printf("script failed:\n %s\n", lua_tostring(L, -1));
}
else
{
console_printf("script finished\n");
printf("script finished\n");
}
give_semaphore(sem);
}
else
{
console_printf("lua semaphore timeout (another task is running this script)\n");
err_printf("lua semaphore timeout (another task is running this script)\n");
}
}
}
......@@ -100,20 +100,20 @@ static MENU_SELECT_FUNC(script_menu_select)
{
if(docall(L, 2, 0))
{
console_printf("script error:\n %s\n", lua_tostring(L, -1));
err_printf("script error:\n %s\n", lua_tostring(L, -1));
}
give_semaphore(sem);
}
}
else
{
console_printf("select is not a function\n");
err_printf("select is not a function\n");
give_semaphore(sem);
}
}
else
{
console_printf("lua semaphore timeout (another task is running this script)\n");
err_printf("lua semaphore timeout (another task is running this script)\n");
}
}
}
......@@ -198,7 +198,7 @@ static MENU_UPDATE_FUNC(script_menu_update)
}
else
{
console_printf("lua semaphore timeout (another task is running this script)\n");
err_printf("lua semaphore timeout (another task is running this script)\n");
}
}
}
......@@ -692,7 +692,7 @@ static void load_menu_entry(lua_State * L, struct script_menu_entry * script_ent
}
else
{
console_printf("invalid choice[%d]\n", choice_index);
err_printf("invalid choice[%d]\n", choice_index);
menu_entry->choices[choice_index] = NULL;
choices_count = choice_index;
}
......@@ -742,7 +742,7 @@ static void load_menu_entry(lua_State * L, struct script_menu_entry * script_ent
}
else
{
console_printf("warning: could not create metatable submenu");
err_printf("warning: could not create metatable submenu");
}
for (submenu_index = 0; submenu_index < submenu_count; submenu_index++)
......@@ -775,20 +775,20 @@ static void load_menu_entry(lua_State * L, struct script_menu_entry * script_ent
}
else
{
console_printf("warning: could not get metatable submenu");
err_printf("warning: could not get metatable submenu");
}
lua_pop(L, 2);
}
else
{
console_printf("warning: could not get parent metatable");
err_printf("warning: could not get parent metatable");
}
lua_pop(L, 1);//userdata
}
else
{
console_printf("invalid submenu[%d]\n", submenu_index);
err_printf("invalid submenu[%d]\n", submenu_index);
}
lua_pop(L, 1);
}
......
......@@ -70,14 +70,14 @@ static void lua_prop_task(int unused)
else lua_pushinteger(L, *((uint8_t*)(lua_prop->prop_value)));
if(docall(L, 2, 0))
{
console_printf("script prop handler failed:\n %s\n", lua_tostring(L, -1));
err_printf("script prop handler failed:\n %s\n", lua_tostring(L, -1));
}
}
give_semaphore(sem);
}
else
{
console_printf("lua semaphore timeout (another task is running this script)\n");
err_printf("lua semaphore timeout (another task is running this script)\n");
}
}
}
......@@ -647,4 +647,4 @@ const luaL_Reg propertylib[] =
{NULL, NULL}
};
LUA_LIB(property)
\ No newline at end of file
LUA_LIB(property)
......@@ -34,11 +34,11 @@ static void lua_run_task(struct lua_task_func * lua_task_func)
{
if(docall(L, 0, 0))
{
console_printf("script failed:\n %s\n", lua_tostring(L, -1));
err_printf("script failed:\n %s\n", lua_tostring(L, -1));
}
else
{
console_printf("script finished\n");
printf("script finished\n");
}
luaL_unref(L, LUA_REGISTRYINDEX, lua_task_func->function_ref);
}
......@@ -46,7 +46,7 @@ static void lua_run_task(struct lua_task_func * lua_task_func)
}
else
{
console_printf("lua semaphore timeout (another task is running this script)\n");
err_printf("lua semaphore timeout (another task is running this script)\n");
}
free(lua_task_func);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment