(closes issue #13558)

Reported by: mnicholson

Considering that the example extensions.lua used nothing but ["12345"] notation,
and that the resulting error message: 

[Sep 24 17:01:16] ERROR[12393]: pbx_lua.c:1204 exec: Error executing lua extension: attempt to call a nil value

is not very informative as to the nature of the problem, I think this bug
fix is a big win!





git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@144482 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.2
Steve Murphy 17 years ago
parent 82abf73a80
commit f8ddaae70b

@ -1193,22 +1193,25 @@ static int lua_find_extension(lua_State *L, const char *context, const char *ext
/* step through the extensions looking for a match */ /* step through the extensions looking for a match */
for (i = 1; i < lua_objlen(L, context_order_table) + 1; i++) { for (i = 1; i < lua_objlen(L, context_order_table) + 1; i++) {
int e_index, isnumber, match = 0; int e_index, e_index_copy, match = 0;
const char *e; const char *e;
lua_pushinteger(L, i); lua_pushinteger(L, i);
lua_gettable(L, context_order_table); lua_gettable(L, context_order_table);
e_index = lua_gettop(L); e_index = lua_gettop(L);
isnumber = lua_isnumber(L, e_index);
if (!(e = lua_tostring(L, e_index))) { /* copy the key at the top of the stack for use later */
lua_pop(L, 1); lua_pushvalue(L, -1);
e_index_copy = lua_gettop(L);
if (!(e = lua_tostring(L, e_index_copy))) {
lua_pop(L, 2);
continue; continue;
} }
/* make sure this is not the 'include' extension */ /* make sure this is not the 'include' extension */
if (!strcasecmp(e, "include")) { if (!strcasecmp(e, "include")) {
lua_pop(L, 1); lua_pop(L, 2);
continue; continue;
} }
@ -1223,34 +1226,28 @@ static int lua_find_extension(lua_State *L, const char *context, const char *ext
* match, 2 on earlymatch */ * match, 2 on earlymatch */
if (!match) { if (!match) {
lua_pop(L, 1); /* pop the copy and the extension */
lua_pop(L, 2);
continue; /* keep trying */ continue; /* keep trying */
} }
if (func == &matchmore && match == 2) { if (func == &matchmore && match == 2) {
/* We match an extension ending in '!'. The decision in /* We match an extension ending in '!'. The decision in
* this case is final and counts as no match. */ * this case is final and counts as no match. */
lua_pop(L, 3); lua_pop(L, 4);
return 0; return 0;
} }
/* remove the context table, the context order table, and the /* remove the context table, the context order table, the
* extension (or replace the extension with the corisponding * extension, and the extension copy (or replace the extension
* function) */ * with the corresponding function) */
if (push_func) { if (push_func) {
/* here we must convert the exten back to an integer lua_pop(L, 1); /* pop the copy */
* because lua_tostring will change the value on the
* stack to a string */
if (isnumber) {
int e_int = lua_tointeger(L, e_index);
lua_pop(L, 1); /* the exten should be the top of the stack */
lua_pushinteger(L, e_int);
}
lua_gettable(L, context_table); lua_gettable(L, context_table);
lua_insert(L, -3); lua_insert(L, -3);
lua_pop(L, 2); lua_pop(L, 2);
} else { } else {
lua_pop(L, 3); lua_pop(L, 4);
} }
return 1; return 1;

Loading…
Cancel
Save