lua-users home
lua-l archive

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

> What am I doing wrong?
> Thank you.

You forgot to add lua_call() or lua_pcall(). See below (untested!):

function call_add_xy(L: Plua_State; x, y: Double): Double;
   // Push functions and arguments:
   lua_getglobal(L, 'add_xy');  // Function to be called.
   lua_pushnumber(L ,x);        // Push 1st argument.
   lua_pushnumber(L, y);        // push 2nd argument.
   If lua_pcall(L, 2, 1, 0) = 0 then
     Result := lua_tonumber(L, -1)
     Assert(false, 'Call failed!');
   // pop returned value:
   lua_pop(L, 1);