[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua and composition
- From: Petri Häkkinen <petrih3@...>
- Date: Sat, 4 Mar 2017 15:51:31 +0200
On Mar 4, 2017, at 3:24 PM, "Soni L." <email@example.com> wrote:
> But can you do
> block_in_world = world:get_block(pos)
> if block_in_world.inventory then
> block_in_world:inventory.set_item(1, item)
> (for a minecraft-like game)
> Keep in mind each block in the world may store inventory differently (or even store it elsewhere!), so you can't just assume all inventories will behave the same (that is, you can't use a static function unless you're calling a dynamic function, in which case why not call the dynamic function directly?).
Sure, if you really need polymorphism, then you need some sort of dynamic dispatch. Luckily first class functions in Lua make this really simple.