Next: Acknowledgments Up: 7 Some Examples Previous: 7.5 A CFunction

7.6 Calling Lua Functions from C

This example illustrates how a C function can call the Lua function remove_blanks presented in Section 7.2.

void remove_blanks (char *s)
{
  lua_pushstring(s);  /* prepare parameter */
  lua_call("remove_blanks");  /* call Lua function */
  strcpy(s, lua_getstring(lua_getresult(1)));  /* copy result back to 's' */
}


Next: Acknowledgments Up: 7 Some Examples Previous: 7.5 A CFunction