Hi Kevin, thanks for replying.
So the problem variable is a pointer to a string of kind c_char. It is defined as len=: I have not seen this syntax before. I tried setting a hard coded max length but it failed. Not sure if that is what you meant with upper bound? I'll paste some code here to make it clearer.
lua_result is defined like this:
Code: Select all
character(kind=c_char, len=:), pointer :: lua_result
It causes a bounds error at this line because lua_result has length 1 and result_len at this point is greater than 1 (actually 14 in my case):
Code: Select all
matcstr(1:result_len) = lua_result(1:result_len)
I naively tried defining it like this:
Code: Select all
character(kind=c_char, len=MAX_NAME_LEN), pointer :: lua_result
But then it failed a couple of lines earlier, at this line:
Code: Select all
lua_result => lua_popstring(LuaState, result_len)
I think this is because lua_popstring wants to return a length 1 pointer with the meaningful length of data to which the pointer points being given by result_len. But I already defined lua_result as having length more than one.
So if there is a way to modify lua_popstring or lua_tolstring to return something whose length matches the length of the data to which it points (or which it contains, if it could be an allocatable string for example) this might be a solution.
Curiously lua_tolstring contains this unused variable:
Code: Select all
character(kind=c_char, len=:), allocatable :: s
I guess whoever wrote this routine in Lua.F90 tried to use an allocatable string but failed and used a pointer instead...
Any further thoughts appreciated!
Regards,
Rupert