lua-users home
lua-l archive

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

Try this;

function sum(l: plua_state):integer;
x, y: integer;
x:= lua_tonumber(l, 1);
y:= lua_tonumber(l, 2);
lua_pushnumber(l, x+y);
result := 1;

Might not be completely correct, bit rusty on my Pascal after two decades. :)


Sent from my espressomachine

luciano de souza <> 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+}
>function sum(l: plua_state):integer;
>x, y: integer;
>lua_tonumber(l, x);
>lua_tonumber(l, y);
>lua_pushnumber(l, x+y);
>result := 1;
>function luaopen_opr(l: plua_state):integer;
>r: array[0..1] of luaL_reg;
>l := lua_open;
>r[0].name := 'sum';
>r[0].func := @sum;
>luaL_openlib(l, 'opr', @r, 0);
>result := 1;
>In the Lua code, I would like to do it:
>print(opr.sum(3, 5))
>I follow C API and I believe the fact it was writen in Pascal won't
>create difficulties for the discutions.
>These are my first steps in C API. Do they seem to be wrong? Does
>someone have any tip for me?