Skip to content

bad argument when using localize ngx.re.find #1580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zcong opened this issue Aug 23, 2019 · 3 comments
Closed

bad argument when using localize ngx.re.find #1580

zcong opened this issue Aug 23, 2019 · 3 comments

Comments

@zcong
Copy link

zcong commented Aug 23, 2019

openresty-1.13.6.2
I wrote function like this

function _M.find_in_string(source_string, matching_string)
    return ngx.re.find(source_string, matching_string, "jo")
end

and I try to replace the ngx.re.find with localize var like this

local ngx_re = ngx.re
local ngx_re_find = ngx_re.find
function _M.find_in_string(source_string, matching_string)
    return ngx_re_find(source_string, matching_string, "jo")
end

the first version find_in_string(nil, "") will return nil
the second version find_in_string(nil, "") will raise an exception: bad argument #1 to 'find_in_string' (string expected, got nil)

why is that?

@cuiweixie
Copy link
Contributor

the second version call the old lua-c version ngx.re.find, and the first version call the ffi base (after requre "resty.core") version will cause this. by the way the newest version of openresty load the ffi function at lua vm init.

@thibaultcha
Copy link
Member

Considering this answered. Thanks for the help @cuiweixie.

@jils2013
Copy link

jils2013 commented Sep 2, 2019

should we remove localize for ngx.re.find?

the second version call the old lua-c version ngx.re.find, and the first version call the ffi base (after requre "resty.core") version will cause this. by the way the newest version of openresty load the ffi function at lua vm init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants