[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Compiling a Pascal DLL for Lua
- From: luciano de souza <luchyanus@...>
- Date: Tue, 1 Mar 2011 09:39:58 -0300
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
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?
function prandom(l: plua_state):integer;
n := random(100);
function lua_opentest(l: plua_state):integer;
lua_register(l, 'random', prandom);
lua_opentest := 1;
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