2

I need help integrating lua in my game. I know only a little about lua, since I just started learning scripting (in general). I've read tutorials about lua, but most of them are only tell me how to bind lua in c++ code (which I've managed to do that with LuaBind), or explaining features in lua.

Let's say I have a "Player" class and "Obstacle" class. Obstacle class have these functions :


class Obstacle {
  // ... member vars

  // functions that will behave differently based on script :
  void onTouchPlayer(Player* player);
  void onUpdate(float deltaTime);
}

onTouchPlayer and onUpdate is meant to behave differently based on script.

What confuses me is what to write in the script, and how to call it in c++? If I already have Player class exported to Lua with LuaBind, how can I, for example, kill player at onTouchPlayer() and move the obstacle randomly at onUpdate function with lua?

Radi
  • 103
  • 1
  • 4

2 Answers2

2

There are lots of tutorials out there dealing with that. A google search will give you some.

I personally liked this one:

http://csl.sublevel3.org/lua/

kikito
  • 51,734
  • 32
  • 149
  • 189
-1

The following page of the Lua Development Guide (5.0) tells you how to call lua functions from the C environment.

http://www.lua.org/pil/25.2.html

James
  • 5,355
  • 2
  • 18
  • 30