[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Design mistakes in mixed C/C++ and Lua projects (was: How can I be sure LuaJIT is working?)
- From: Xavier Wang <weasley.wx@...>
- Date: Fri, 21 Oct 2011 09:37:02 +0800
2011/10/21 Mike Pall <mikelu-1110@mike.de>:
> Kevin T. Ryan wrote:
>> > ...
>> > Also have a look at the number of Lua->C and C->Lua calls via the
>> > classic Lua/C API. These are expensive and neither a C compiler,
>> > nor a Lua compiler can optimize across the language border. Most
>> > of the time will be wasted in the API calls.
>>
>> Just wondering - if someone ran into this do you think it would be
>> symptomatic of:
>>
>> 1. Not truly choosing a language to implement the project in (eg., too
>> much mixing between the 2 languages).
>> 2. Poor implementation (e.g., probably a better way to reduce the
>> number of API calls).
>> 3. Something else?
>>
>> Maybe it's problem specific, but I guess I'm just wondering if you
>> have seen this happen to yourself or someone else and what the root
>> cause was (and if any generalizations could be made from such
>> experiences).
>
> <rant>
>
> Scenario #1:
>
> A game company starts out with a giant, over-architected C++ code
> base ("Our games will NEVER need scripting"), outgrow their config
> files, toy with the idea of implementing their own scripting
> language, but some guy overheard something about Lua at their
> previous job.
>
> Now they throw some expensive Lua/C++ binding generators at it
> (because their C++ codebase is a big pile of dung), start writing
> some code in Lua that mostly calls out to C++, see it running slow
> as molasses and (of course) blame Lua.
>
> Some other guy read about LuaJIT somewhere, so they give it a try,
> but obviously don't get a speedup and (of course) blame LuaJIT.
> They write angry letters to me, I try to politely explain to them
> that their design leaves something to be desired, they blame the
> messenger.
>
So, this is just our situations. We have a pure C++ platform on
Symbian. and in this project we decide to use Lua for actually
development. so we used tolua++ ...
My question is, Yes, to call C++ functions from Lua is slow, so, is
there any good solutions about the using of Lua? you know, except for
arithmetic, all root libraries are implement by C, even if print or
select. if the C/Lua switch is slow, then what things in Lua is fast?
pure Lua operations with tables? is that faster than a well designed
array like userdata? (like intarray module)
More precised, We want to use Lua to write a phone 2D Game, so could
you talk about the best design you think? notice that the render is
the most busy part of the game. and Is Lua suitable using to write a
render of Game? just like this:
function onpaint(g)
g:Clear()
g:DrawImage(img, 0, 0)
......
g:DrawText("hello", 100, 100)
.....
g:End()
end
if you think using a lot of lua/c switch is a bad design, so please
tell me how to implement a onpaint event in Game?
- write it in pure C? Oh My God, then why I used Lua? if I *MUST*
write any C/Lua bother to C, then I couldn't find any where I could
use Lua in game.
- write it in pure Lua? first is the speed, maybe LuaJIT may fast,
then, using Lua to do actually render? use Lua to compute the FFA
algorithm? using Lua to clear a surface (using for i = 1, 10000?), I
think it's crazy. I just using Lua to write a Game, but I don't want
using a *PURE* lua to write a game. Maybe I must using Lua in kernel
module to get the input from user?
- write it with the idiom that Lua produce data and C process the
datas. yes, It's a good idea, but, what format we used for data? like
this?
function onpaint(g)
local cmd = {}
cmd[#cmd+1] = {"clear"}
cmd[#cmd+1] = {"drawimage", img, 0, 0}
.....
g:DoCmd(cmd)
end
but it has some problem: it may need create many of tables. If you
don't want tables the only choices is using string or userdata. using
string is a bad idea: because it may course at least one copies of
string, it still waste memory (and slow), and userdata? if we use a
userdata to produce data, why we just use g directly (also a
userdata)?
So, Yes, our framework is only design by C++ used before. and now we
used Lua, and heavily crossed C/Lua bother. and we think the game is
slow (yes!), but, WHEN you are saying it's bad to cross C/Lua bother,
could you give us some of advice how to worked with thus a framework
with Lua? is that possible? or if it impossible, is the Lua the
fastest language that on the C/Lua bother? if Lua is not, then why Lua
is not as fast as other languages in crossing C/Lua bother?
and, at last, if we want to developed such a C++ framework that the
purpose is working with Lua, then How did we do? in a simple sample:
how to binding (or even implement) a C render for Lua? to makes calls
such as DrawImage or glVertex call will fast?
Thank you and sorry for my rude :-(