lua-users home
lua-l archive

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

On Jun 25, 2014, at 10:47 PM, Austin Einter <> wrote:

> Thanks, I modified as per suggestion, now script looks as below
> function modify_content_length(msg, length)
>     local offset = string.find(msg, "Content-Length", 1, true)
>     if(offset == nil) then
>     else
>         msg1 = msg:gsub("(Content%-Length%s*:%s*)\r","%1"..n.."\r")
>         print("msg1 = ",msg1)
>     end
> end
> msg = [=[INVITE\r\nContent-Length : \r\n\r\nv=0\r\n]=]
> modify_content_length(msg, string.len(msg))
> Looks now getting error because of n
> Error ->
> lua5.2: string_test.lua:7: attempt to concatenate global 'n' (a nil value)
> stack traceback:
>     string_test.lua:7: in function 'modify_content_length'
>     string_test.lua:15: in main chunk
>     [C]: in ?
> Regards
> Austin

You are not defining the variable `n` to be any value, hence the error message saying you are trying to concatenate a global `n`, which is a nil value. You need to assign a value to `n` before you can concatenate it, or use a different variable.

Might I suggest reading the documentation[1] and/or books to gain a better understanding of the language, especially the fundamentals like string handling and variable usage... it is worth the time, especially if you plan to use Lua for more than just this one script.

Also, please note that list netiquette is to avoid top-posting (posting your reply above the quoted text).

Good luck with your Lua scripting! :)