lua-users home
lua-l archive

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


Hello,

	Hi.

> There seem to be many pascal scripting
components in delphi, but if possible I would like to use something I
can also use stand-alone (for those occasions where a full-fledged
delphi app would be over-kill).

	Yes, there are lots of them. But in the end, they are all the same thing.

However, I am not a C programmer and I find it hard to get a feel for
what is possible when it comes to linking lua to other languages than
C.

You are not alone. The biggest problem about Lua [community] is that everybody thinks you have a C compiler and also have knowledge on how to use it wisely. No binaries for us (and no donnuts for Orkut's server) :(

[Please, no comments about how I'm stupid or lazy, ok? ;)]

I would be very interested in any information you have on integrating
lua with Delphi.

It's very simple. Look at LuaForge.net and you will find an up-to-date binary with header [Lua 5.0.2] translated to Pascal ready to use. If I recall right, the name is LuaPas.

How do the lua environment and the delphi environment
integrate? What are the limitations? Is a two-way binding doable /
elegant / stable / hackish ?

Good question. The main difference is that all Lua's external functions are cdecl'ed. That just mean that you will have to get used to write 'cdecl;' after many functions :). I myself don't see any other limitation (except 'that' quoted above).

About the two-way binding, it is possible [partially at least] but can be a little tricky in the beggining (what isn't?). I haven't seen any project to automate the proccess of binding between Lua and Delphi, so I made one myself (there were a discussion some months ago about a possible 'topascal', but ended up with nothing). It's not pretty nor full optimized, but works.

I was about to send some details about my solution, but the message was getting very big (just like Delphi executables - you start with something small and then when you see, it became a 6MB snowball).

In short, what I would say is that everything is doable in an elegant way, except events. Basically the main problem is that the pascal calling convention is far different from the cdecl calling convention. It is possible, but I don't know if the costs are worthy it.


In short, I would very much like to hear whatever information, war
stories, source examples you want to share, urls to other information
that helped you out with the problems you had implementing, the lot.

Well, I can send you what I have, but you will probably throw it in the trash, because it's still a little messy -- except for the TLuaObject object (not class). It does nothing except cutting the

" lua_<something>(L,...) "

to

" Lua.Something(...) "

Very efficient to use. With just a typecast, you have:

with TLuaObject(L) do
begin
	PushString('Me');
	PushString('Too');
	RawSet(LUA_GLOBALSINDEX);

	// Or...
	SetNamedString('Me', 'MeToo', LUA_GLOBALSINDEX);
end;



--rb