Acess duplicate variables in lua to c

Viewed 47

I have sprite class in c binding to lua and in lua code i have some bullets, and all the bullets have the event update but if we create multiple bullets how can we access each bullet with the same name in c.

  for i = 1, 5 do
            bullet= Sprite.new()
            bullet:Name("bullet")
   end

in c i call lua_getglobal(L, "bullet"); and i get just one from the top of the stack , there is any way to call individual bullets from lua to c. thank you

sorry my English.

1 Answers

What you need to do is separate the name from the actual sprite name, otherwise, there's no way to identify the bullet since they all have the same name.

Another thing you could do is store them in a global table called "bullets" via table.insert.

I hope this helps

Related