lua-users home
lua-l archive

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


2009/11/19 John Hind <john.hind@zen.co.uk>:
> I have been trying to improve the error reporting in some of my code and
> came across another slightly rough area of Lua. I have been using
> luaL_loadstring to load text from a Windows EXE named resource. Errors get
> reported something like:
>
>
>
> [string: “x = x + 1”]:1: attempt to perform arithmetic on global ‘x’ (a nil
> value)
>
>
>
> I tried using luaL_loadbuffer, specifying the name of the resource as the
> last parameter (chunk name). But it still insists on adding the
> inappropriate ‘string’ prefix and enclosing my supplied name in quotes:
>
>
>
> [string: “myres”]:1: attempt to perform arithmetic on global ‘x’ (a nil
> value)
>
>
>
> Even using lua_load with a custom lua_Reader function, the unwanted
> prefixing is still done, so it seems to be impossible to get “under” this
> unwanted processing with the published API.
>

Try prefixing the chunk name you pass with '@', e.g. '@myres'. Worked
that one out the hard way :)

Matthew