From a5a95c36d7db738393f41691c5d68a378a9860c6 Mon Sep 17 00:00:00 2001 From: Avi Date: Fri, 8 Jan 2016 11:50:59 +0000 Subject: Fix error message when no args are passed --- cinterface.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cinterface.lua b/cinterface.lua index c6b5c84..e2e2050 100644 --- a/cinterface.lua +++ b/cinterface.lua @@ -118,7 +118,12 @@ function CInterface:__addchelpers() table.insert(txt, '#include "string.h"') table.insert(txt, 'static void str_arg_types(lua_State *L, char *buf, int n) {') table.insert(txt, ' int i;') - table.insert(txt, ' for (i = 1; i <= lua_gettop(L); i++) {') + table.insert(txt, ' int nargs = lua_gettop(L);') + table.insert(txt, ' if (nargs == 0) {') + table.insert(txt, ' snprintf(buf, n, "no arguments provided");') + table.insert(txt, ' return;') + table.insert(txt, ' }') + table.insert(txt, ' for (i = 1; i <= nargs; i++) {') table.insert(txt, ' int l;') table.insert(txt, ' const char *torch_type = luaT_typename(L, i);') table.insert(txt, ' if(torch_type && !strncmp(torch_type, "torch.", 6)) torch_type += 6;') -- cgit v1.2.3