A bit about LUA

BlitzMax Forums/BlitzMax Programming/A bit about LUA

Sanctus(Posted 2009) [#1]
Hey guys.
I'm working on a space invaders type game right now and I want it to be very flexible so I was thinking about using lua for AI and for the weapons.
I've never done this before but I want to do it right from the start.
Is it wiser to create a lot of VM's for each entity or just one and set the variables before each entity?.


Htbaa(Posted 2009) [#2]
I'd say use 1 VM and just pass the blocks of code to it you want to execute. I say blocks because it's smart to keep the code you execute private and hidden from the rest of the Lua code you execute. That way you keep memory usage in your VM low and you can't accidentally set some property to an unwanted value because you forgot to set in your last call, but it was still available because of the last chunk of code that was executed.


Zeke(Posted 2009) [#3]
http://www.blitzmax.com/Community/posts.php?topic=85952


Sanctus(Posted 2009) [#4]
Why thank you.
That example will help me a lot tomorrow when I'll try to implement the AI.


N(Posted 2009) [#5]
Creating a bunch of VMs is a waste. Create a single VM and spawn multiple threads with separate environments if you want (same effect with better results since you don't have about 8,000 different garbage collectors running).

I'd take a look at Unity's model and try to emulate it, since it's fairly successful and I rather like the way that works.


Tommo(Posted 2009) [#6]
Unity scripts are compiled into native mono DLL, Even their "Javascripts" or "Booscripts" are both compiled into native, so they can easily run seamlessly with other "native" components.

I wrote something similar in Lua, with a slightly modified LuGI which uses seperated VMT for each bmxtype. The VMTs are wrapped as "lua class" during intialization(assign a lua-class-mt to VMT). After that, I use a "Virtual Reflection" for lua classes, with it I can copy/persist/edit lua objects, just like other bmx objects.


N(Posted 2009) [#7]
I wrote something similar in Lua, with a slightly modified LuGI which uses seperated VMT for each bmxtype. The VMTs are wrapped as "lua class" during intialization(assign a lua-class-mt to VMT). After that, I use a "Virtual Reflection" for lua classes, with it I can copy/persist/edit lua objects, just like other bmx objects.
I'd be interested in seeing that if you ever decide to release the source code.


Tommo(Posted 2009) [#8]
I'd be interested in seeing that if you ever decide to release the source code.

When I'm ready to do so, I will let you know. :)