lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2014-06-27 12:51 PM, "Austin Einter" <austin.einter@gmail.com> wrote:
>
> I changed the order , that is first pushing string, next pushing length.
> Same crash observed.
>
> Austin
>
>
> On Fri, Jun 27, 2014 at 10:16 PM, Oliver Kroth <oliver.kroth@nec-i.de> wrote:
>>
>> No,
>>
>> this gives the reverse order.
>>
>> --
>> Oliver
>>
>> Am 27.06.2014 18:41, schrieb Austin Einter:
>>>
>>> I am bit new, but I hope push order is fine. First I push length, next msg.
>>> And in function, my 1st arg is msg, next arg is length.
>>>
>>> Is not this order right?
>>>
>>> BR
>>> Austin
>>>
>>>
>>> On Fri, Jun 27, 2014 at 10:02 PM, Daurnimator <quae@daurnimator.com> wrote:
>>>>
>>>> On 27 June 2014 12:17, Austin Einter <austin.einter@gmail.com> wrote:
>>>>>
>>>>> const char *c_function = "function modify_content_length(msg, length) "
>>>>>   lua_getglobal(L,"modify_content_length");
>>>>>   lua_pushinteger(L,length);
>>>>>   lua_pushstring(L, msg);
>>>>>   lua_call(L,2,1);
>>>>
>>>>
>>>> I haven't run your code, but I can see that you're pushing arguments in the wrong order.
>>>>
>>>> Otherwise, you should use pushlstring (with your length) instead of pushstring;
>>>> Also, passing the length as a parameter itself is pointless: use the length operator '#'
>>>
>>>
>>
>

Check the return values from luaL_pcall and luaL_loadstring to see if they've succeeded. If there's a syntax or runtime error in your code, you'll end up calling nil here, which may not throw an error when done from C, but just crash.

You can compile Lua with API checking enabled, then it will give detailed information when passing wrong things to the API, instead of crashing. (This of course is a bit slower, thus why it's not default.)