[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why need to call "priming lua_pcall()" before running function in Lua script
- From: Coda Highland <chighland@...>
- Date: Thu, 2 Jul 2015 23:45:07 -0700
On Thu, Jul 2, 2015 at 11:39 PM, Nan Xiao <firstname.lastname@example.org> 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.