[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua Performance questions
- From: Christopher Eykamp <chris@...>
- Date: Wed, 23 Sep 2009 10:51:57 -0700
Actually, having read others' responses, I now see you were trying to
run an entire script, not just a function, as I initially supposed.
Christopher Eykamp wrote:
Essentially, yes. Here's a snippet from Bitfighter, a game I'm
developing that uses Lua scripted robot players. To get a robot's
name, I call a function in the script called getName(). Here is the
code I use:
// Run the getName() function in the bot (will default to the one in
robot_helper_functions if it's not overwritten by the bot)
if (!lua_isfunction(L, -1) || lua_pcall(L, 0, 1, 0)) // Passing
0 params, getting one back
mPlayerName = "Nancy";
logError("Robot error retrieving name (%s). Using \"%s\".",
lua_tostring(L, -1), mPlayerName.getString());
mPlayerName = lua_tostring(L, -1);
I do not claim to be a master at integrating Lua with C++, but there
are several working examples of working integration in my codebase.
You can access it via Sourceforge, and the files of most interest will
likely be robot.cpp and luaLevelGenerator.cpp.
do you mean I can load a script called "melee.lua" and then call
is that it?
2009/9/23 Luiz Henrique de Figueiredo <firstname.lastname@example.org
> I see.. so I can load all scripts at the beginning or at least
be sure to
> load at least one time before calling the function.
> But I have to be sure that every script has a different
> otherwise I would be unable to call it. Is not it?
The script itself is an anonymous function.
God$ g++ -o earth earth.cpp -O3 -lanimals -lplants -lvirus