lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 18/10/2006, at 10:07 PM, Koch, Chris, VF-DE wrote:

Just want to know if it is possible to
LUA to use functions of a compiled win32
binary to control the program.
I mean for example to let a character move
to x,y coord by calling the subroutine within
the binary for moving.

I heard this is possible if the program uses
LUA on it`s own. But if not?!

I assume you don't have the source to this program? If it exposes entry points (like, it is a DLL) then you can make stubs that let Lua call them.

For example, say there is a routine in the binary that does MovePlayer (x, y) that can be called from C.

Here is how you might interface with it:

int move_player (lua_State * L)
  {
  double x = luaL_checknumber (L, 1);  // get x  (argument 1)
  double y = luaL_checknumber (L, 2);  // get y  (argument 2)
  int result = MovePlayer (x, y);   // call your binary
  lua_pushnumber (result);          // save result of move
  return 1;                         // our function returns 1 result
  }

You also need to install "move_player" into the Lua space. Read the documentation for how to do that.

- Nick