[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: pascal (delphi) implementation
- From: jz@... (Jacob Zielinski)
- Date: Fri, 17 Sep 1999 17:26:40 -0700
Hello all,
I'm attempting to access Lua through Pascal. I've compiled a DLL in VC6 and
used a '__declspec(dllexport)' to export functions. I assume this uses the
stdcall calling convention.
I can call the basic functions like lua_open, lua_dofile. My problem occurs
when I try to register a Pascal function. Passing my pascal function to
lua_pushcclosure() causes it to get called. Switching into assembler view
shows that the right before RET is called (at the end of lua_pushcfunction),
the address on top of the stack is the address to my pascal function. This
explains why it gets called, but not why it on top of the stack. It seems as
if there was an extra POP somewhere. This made me suspect I may have a
problem with my calling convention. I'm confused and I don't know much C.
Maybe I am doing something stupid here. Maybe someone can help.
I have included the relevant code below:
const
luadll = 'lua.dll';
type
lua_cfunction = procedure; stdcall;
procedure lua_pushcfunction(f: lua_cfunction);
procedure lua_pushcclosure(f: lua_cfunction; n: int); stdcall; external
luadll;
procedure lua_setglobal(name: PChar); stdcall; external luadll;
procedure lua_register(n: PChar; f: lua_cfunction);
begin
lua_pushcfunction(f);
lua_setglobal(n)
end;
procedure lua_pushcfunction(f: lua_cfunction);
begin
lua_pushcclosure(f, 0);
end; { <--- before RET occurs, top of stack has f() address instead of
calling address }