lua-users home
lua-l archive

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


On Thu, Jul 2, 2015 at 11:39 PM, Nan Xiao <xiaonan830818@gmail.com> wrote:
> Hi all,
>
> After reading "Calling Lua From a C Program", I see it's need to call
> "priming lua_pcall()" or
> "priming lua_dofilel()" before using "lua_getglobal()" to get a function and
> run it successfully.
> Or the program will complain "attempt to call a nil value".
>
> But after googling and going through "Programming in Lua", I can't find what
> is under the
> hood. Could anyone can explain why need the the magical "priming lua_pcall"?
>
> Thanks very much in advance!
>
> Best Regards
> Nan Xiao

It's sort of a weird term. I've never seen it used before. But from
the context of the page you linked, I can figure it out.

What it's actually saying is that you PROBABLY want to run some Lua
code when you first create the state, so that you can do things like
create global variables and define Lua functions that you want to
offer to the other Lua code that you will be running later.

This author seems to have invented the term because he didn't realize
that the examples in the documentation were just simple examples of
how things might look in use, and not intended as standalone code that
you can use directly. So for example, when he got an error saying
"attempt to call a nil value" it's because he never did anything to
create the function that he was trying to call.

Honestly I would suggest avoiding this document and looking for
something better to work from.

/s/ Adam