Re: luaL_loadbuffer API cannot deal with shebang
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: luaL_loadbuffer API cannot deal with shebang
 
- From: Jim <djvaios@...>
 
- Date: 2019年5月22日 22:12:29 +0200
 
On 5/22/19, Baozeng <sploving1@gmail.com> wrote:
> I have a simple Lua file, for example, hello.lua. The contents of the file
> starts with a shebang
> I first read the file content into a buffer. And then use luaL_loadbuffer
> and lua_pcall to call the function. However, I found that luaL_loadbuffer
> cannot return normally because it does not deal with the buffer started
> with a shebang.
how about
int r = luaL_dofile ( ... ) ;
??
the result should be contained in the variable "r" now.
when loading the file content into a buffer you should save the
start of the second line in a pointer if the file starts with a shebang
("#!") and then call load_string/buffer from that advanced position
via the new pointer value instead of the original start position.
this is due to Lua not using "#" to indicate comments.