lua-users home
lua-l archive

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


>This is interesting, at least to see how binding to a libary is done.

The binding was done by manually fixing the output of Lua script that read
pdflib.h. The script is at the end of the message.

>- Like John noticed, unless you don't plan to change it, you should put some
>versioning on the name of the file to download.

I only plan to change it when a new Lua version comes out. When 5.0 comes out,
I'll think of a scheme for the old versions. Something like lua-pdflib-4.0.

>Do you plan to use it to generate Lua documentation?

Not really. I don't know whether pdflib's documentation was written using it;
I'd be really impressed if it was.

>Thank you for this useful code.

You're welcome. Thanks for the comments.
--lhf

RTEMPLATE=[[
static int L_XXX(lua_State *L)
{
 AAA rc = XXX(BBB);
 lua_pushnumber(L,rc);
 return 1;
}
 lua_register(L,"XXX",L_XXX);
]]

VTEMPLATE=[[
static int L_XXX(lua_State *L)
{
 AAA XXX(BBB);
 return 0;
}
 lua_register(L,"XXX",L_XXX);
]]

function f(t,n,p)
	--print(t,n,p) do return end
	p=strsub(p,2,-2)..","
	--print("/*",t,n,p,"*/")
	local s
	if t=="void" then s=VTEMPLATE else s=RTEMPLATE end
	local a=gsub(p,","," = getpdf(L,1);\n")
	local b=gsub(p,"(.-)(%w+,)","%2")
	--print(b)
	s=gsub(s,"XXX",n)
	s=gsub(s,"AAA",a)
	s=gsub(s,"BBB",b)
	write(s)
end

T=read"*a"
gsub(T,"\nPDFLIB_API *(.-) *PDFLIB_CALL *\n(.-)(%b())",f)