lua-users home
lua-l archive

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


On Tue, Nov 6, 2012 at 4:02 PM, luciano de souza <luchyanus@gmail.com> wrote:
Hello listers,
I am trying to understand the basic mechanism of Lua stack
registrations. This Pascal code compiled, but I have a run-time error.
As it's an generic error, I could not identify what's wrong.

library opr;
{$calling cdecl}
{$mode objfpc}{$H+}

uses
lua;

function sum(l: plua_state):integer;
var
x, y: integer;
begin
lua_tonumber(l, x);
lua_tonumber(l, y);
lua_pushnumber(l, x+y);
I think this should be:

begin
  x:= lua_tonumber( L, 1 );
  y:= lua_tonumber( L, 2 );
  lua_pushnumber( L, x + y );
  Result:= 1; 
end;


--rb