lua-users home
lua-l archive

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


Hi all,

I want to compile a Pascal DLL to use directly in Lua. As there is a
Lua binding for Pascal, the task is possible. However, I didn't
understand how to do it.

If we talk about a regular program, not a DLL, the steps to use a
Pascal function in Lua would be:
1. to declare the unit Lua;
2. to create a stack with lua_open;
3. to open the standard libraries of Lua with lua_openlibs;
4. to create a Pascal function and push the results on the stack;
5. To register the function to be recognized by Lua environment, using
lua_register;
6. to process the stack in the protected mode with lua_pcall;
7. To close the stack with lua_close.

These steps seemed to be not entirely valid for DLLs. If I understood,
all DLLs directly processable for Lua possesses a initial function
called lua_open[name of the module}. If I have a module named "test",
its initial function will be called "lua_opentest".

Following these ideas, I tried to create a DLL, but I could not
understand some aspects.
1. This is the way to create a Pascal DLL for Lua?
2. Where should I place the lua_open and lua_close functions?

library test;
uses
lua;

function prandom(l: plua_state):integer;
var
n: integer;
begin
randomize;
n := random(100);
lua_tonumber(l, n);
prandom:=1;
end;

function lua_opentest(l: plua_state):integer;
begin
lua_register(l, 'random', prandom);
lua_opentest := 1;
end;

exports
prandom;

begin
end.

This DLL creates a prandom function generating numbers between 0 and
100. In Lua environment, it was named simply "random", so I could do:

x = random()



-- 
Luciano de Souza