lua-users home
lua-l archive

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




Jim <djvaios@gmail.com> 于2019年5月23日周四 上午4:12写道:
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 ( ... ) ;
??


LuaL_dofile is ok. But sometimes users may use luaL_loadbuffer to load a buffer that from 
a file.(There are many users, you cannot decide what they do).  So luaL_loadbuffer should have
the same behavior with luaL_loadfile.
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.



--
     Best Regards,
     Baozeng Ding