lua-users home
lua-l archive

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


2011/7/18 Timothée VERROUIL <dreamothee@hotmail.com>:
>> Well in the single Lua state approach, you can just do something like:
>> -Push the game object "frame" function
>> -Push the object itself any any arguments to the function
>> -Call using lua_call or lua_pcall
>> once for each object that needs to be updated. So there isn't really
>> any *need* for more than one Lua state. As long as you use a decent
>> naming convention, global collisions shouldn't be an issue (and
>> provide a way to share information between objects).
>>
>> However, using more than one state has the advantage that each state
>> can run in its own OS thread. As computers add more CPU cores and
>> become more oriented to parallel processing, being able to take
>> advantage of all those cores is important. If you do this you can have
>> multiple objects updating simultaneously, which should offer a
>> significant speed boost if done well.
>>
>> Of course, you don't need one Lua state per object either. You might
>> create one per CPU core, and then divide your objects into groups and
>> use the single-state approach on each group.
>>
>>
>> --
>> Sent from my toaster.
>
> Hi,
>
> Thanks for your answers.
> But, is their an easy way to create a local variable from C++ to Lua ?
> I just found how to inject global variables with the setglobal function.
> For exemple :
>
> local self = theRefFromC++
>
> And, I don't find how to call a specific function describes in a Lua Script
> For example :
> MyActor = {}
>
> MyActor:Manage(Object)
>
> end
>
> How can I call this function and how can I be sure that there aren't any
> collisions with
> another actor with the same script ?
>
> Thanks,
>
> Tim
>

MyActor:Manage(Object) is just a shortcut for MyActor.Manage(MyActor,
Object), so you can call it that way the same as you'd call any
function.

There's no simple way to create a local variable using the C API, but
of course you can provide a C function that returns whatever you need
and assign that to a local variable as with any function.

-- 
Sent from my toaster.