lua-users home
lua-l archive

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



On 26 Jun 2014 12:14, "Austin Einter" <austin.einter@gmail.com> wrote:
>
> Hi Luiz
> The scriptlooks as below
>
>
> function modify_content_length(msg, length)
>
>     local offset = string.find(msg, "Content-Length", 1, true)
>     if(offset == nil) then
>     else
>         print("offset = " , offset)
>         print(s:gsub("(Content%-Length%s*:%s*)\r","%1"..n.."\r"))    
>     end
>
> end
>
> msg = [===["INVITE\r\nContent-Length:\r\n\r\nv=0\r\n]===]
>
> modify_content_length(msg, string.len(msg))
>
>
> When I execute I get below error
>
> lua5.2: string_test.lua:9: attempt to index global 's' (a nil value)
> stack traceback:
>     string_test.lua:9: in function 'modify_content_length'
>     string_test.lua:18: in main chunk
>     [C]: in ?
>
> Regards
> Austin
>

Replace s:gsub with msg:gsub (msg being the variable you want to call gsub on).

You'll also need to return the result of gsub if you want to use it outside of modify_content_length (strings are immutable, functions like gsub return new strings instead of modifying existing ones).

Regards,
Choonster