Random Chitchat 2012-2016
Working on my graduation project.

At this moment I am investigating whether I can use Lua scripts as components for entities, might be relevant for MCServer as well.

Apparently I have found/come up with a way to allow Lua scripts to keep references to entities across function calls. When the entity is deallocated in C++ the Lua reference is set to NULL (yes, not nil).

Also my approach would use a single lua_State for all scripts and therefore allows inter-script/component communication.
Thanks given by:
Even if they get set to nil, the lua code storing them will fail as soon as it tries to call any function on them.
Thanks given by:
Yeah, that's exactly what I'm aiming for. I want Lua to fail, not my application to crash.


I managed to "sandbox" each loaded script/component like our plugins but in a single lua_State. I still need to test this some more though...

It's also possible to attach Lua data (tables and whatever) to userdata (C++ objects). The Lua data always stays in Lua and will be garbage collected by Lua, it may linger after the C++ object has been deallocated and the Lua reference is set to NULL as long as Lua has a reference to it.

Now I just need to figure out how attach the loaded script to userdata the same way as a script can attach other data to a C++ object. Right now a loaded script is attached to a table to achieve the sandboxing effect, but it should be attached to the C++ object/userdata itself.


Xoft, I sometimes see you mentioning the overhead of bridging between Lua and C++. According to this thread just calling simple C++ functions is actually really fast: http://lua.2524044.n2.nabble.com/Is-it-s...50170.html


Stuff seems to work, I can call both C++ functions and functions declared in Lua that are attached to a component. Interestingly enough the script is stuck in the scope of the component, this means I cannot easily call global functions. I need to store a reference to the global table (_G) in order to call functions on it.
Just printing text turns into _G.print("blabla") as well as table functions _G.table.insert(t, 1) .... that's pretty inconvenient.

I am now thinking of adding a mechanism that first checks if a function exists in the global table and call it, or otherwise call the function in the component table (or other way around) but I'm not sure how much of an impact this will have on performance...
Thanks given by:
I'm discovering the MCServer code:
Code:
// We are custom,
        // We are awesome,
        // We are MCServer.
:D
Thanks given by:
I think tigerw put it in a while ago.
Thanks given by:
FakeTruth, usually I mention the costs in a specific reference frame - for example MCServer's hooks are somewhat costly because each triggering means several map lookups and locking a CS for each called plugin. The C->Lua call itself is cheap, but the "bijou" around it costs enough to make it unusable when the number of calls is on the order of thousands per second.
Thanks given by:
In the MC|Brand plugin message?
Thanks given by:
Having fun trying to make a breeding pluginBig Grin


Attached Files Thumbnail(s)
       
Thanks given by:
(02-18-2014, 03:04 AM)tigerw Wrote: In the MC|Brand plugin message?

Yes.
Thanks given by:
Hurray 100 stars on github. Lets celebrate.
Thanks given by:




Users browsing this thread: 25 Guest(s)