Jump to content

Any headers?


Paul
 Share

Recommended Posts

Do any headers exist for PureBasic? If not I could try to make some if any one is interested.

Hello Paul,

 

The Delphi/Pascal header generator available in the download section can also generate PureBasic headers.

 

Purebasic is not mentionned in the download because it's an alpha version that never went to beta stage for now.

 

I'm not a Purebasic programmer so there are probably many errors in the generated Purebasic header code, so i need an experienced Purebasic programmer to test further. Maybe you ?

 

if you test you'll have to provide a list of fixes (or a complete fixed header) to show me what to change in the generator.

 

Welcome dear purebasic adventurer :D

 

PS: remember Purebasic is not officially supported, it's only community support, so if it doesn't work i'm responsible of nothing. Anyway even if the header is not perfect, even if it' only 90% of the job ... 90% is better than nothing, right ?

 

I have to go at work now, i won't be available until this evening

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

Ok, I've done abit of work on the generated header. It works like the c header using macros to load the functions, a better way would be making a proper PureBasic lib (which I wont attempt just yet).

 

I have managed to get a simpe example working

If Initialize()
SetAppTitle("Hello World (window title)")
Graphics(640,480)
CreateWorld()
Repeat
	DrawText("Hello World!",32,32)
	UpdateWorld()
	Flip()
Until keyHit(27) Or AppTerminate()
Terminate()
EndIf	

However I've had to use alot of macro trickery to replace some of PureBasic's own commands as there seems to be no way to exclude libraries.

Also some constants are ignored by PureBasic because they conflict with its own of the same name, thats why I'm using 27 instead of #KEY_ESCAPE.

Edited by Paul

Intel Core i7 975 @ 3.33GHz, 6GB ram, GTX 560 Super OC, Windows 7 Pro 64bit

Link to comment
Share on other sites

Ok, I've done abit of work on the generated header. It works like the c header using macros to load the functions, a better way would be making a proper PureBasic lib (which I wont attempt just yet).

However I've had to use alot of macro trickery to replace some of PureBasic's own commands as there seems to be no way to exclude libraries.

Also some constants are ignored by PureBasic because they conflict with its own of the same name, thats why I'm using 27 instead of #KEY_ESCAPE.

 

Hi Paul, i'm back home

I'm glad you could compile a working sample. I only have purebasic trial and could not compile the header (too big for trial)

 

Maybe the macros could be added automatically to the header by the header generator ? (if you explain me)

 

Look at the header generator template directory. There you can change the constants names in PureBasicLEUnit.txt that is used for main code structure.

 

you should also add TFramework=.i and TScene=.i in PureBasicTypes.txt template as they are missing.

 

and use PureBasicLEWrappersFix.txt to do différent kind of renaming

 

Just tell me if you want to change something

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

Basically to get it working I've added these macros and functions.

To make Initialize and Terminate consistent with the rest of the Leadwerks functions they are too prefixed with Le.

Procedure lePrint(string.s)
Static con=#False

If con=#False
	con=OpenConsole()
EndIf

If con
	PrintN(string)
EndIf
EndProcedure


Procedure ExitFunc(lib.i,f.s)
lePrint("ERROR: unable to find DLL function: "+f)
CloseLibrary(lib)
lePrint("PRESS ENTER TO EXIT.")
Input()
EndProcedure



Global le_lib.i=#Null


Macro DoubleQuote
"
EndMacro

Macro _leInitFunc(a)
Global Le#a#.LE#a=GetFunction(le_lib,DoubleQuote#a#DoubleQuote)
If Le#a=#Null
	ExitFunc(le_lib,DoubleQuote#a#DoubleQuote)
	ProcedureReturn 0
EndIf
EndMacro

Macro _leInitAllFuncs()
_leInitFunc(RegisterAbstractPath);
_leInitFunc(AbstractPath);
_leInitFunc(Graphics);
... and so on...
EndMacro

Macro _leInitialize(le_dll)
le_lib=OpenLibrary(#PB_Any,le_dll)
If le_lib
	_leInitAllFuncs()
Else
	lePrint(le_dll+" can't be loaded.")
EndIf
EndMacro

Procedure.l LeInitialize(allowenginedebug.l=1)
Protected dllfilename.s

If allowenginedebug=1
	CompilerIf #PB_Compiler_Debugger=1 
		dllfilename="engine.debug.dll"
	CompilerElse
		dllfilename="engine.dll"
	CompilerEndIf
Else
	If allowenginedebug=2
		dllfilename="engine.debug.dll"
	Else
		dllfilename="engine.dll"
	EndIf
EndIf
_leInitialize(dllfilename)

ProcedureReturn (#Null<>le_lib)
EndProcedure

Procedure LeTerminate()
LeEndRender()
CloseLibrary(le_lib)
le_lib=#Null
EndProcedure

 

If you do want the commands with their original names (no Le in front). I've made a list of macros that follow like this:

Macro RegisterAbstractPath : LeRegisterAbstractPath : EndMacro
Macro AbstractPath : LeAbstractPath : EndMacro
Macro Graphics : LeGraphics : EndMacro
...

However the must appear after the LeInitialize() function.

Intel Core i7 975 @ 3.33GHz, 6GB ram, GTX 560 Super OC, Windows 7 Pro 64bit

Link to comment
Share on other sites

Basically to get it working I've added these macros and functions.

To make Initialize and Terminate consistent with the rest of the Leadwerks functions they are too prefixed with Le.

 

If you do want the commands with their original names (no Le in front). I've made a list of macros that follow like this:

Macro RegisterAbstractPath : LeRegisterAbstractPath : EndMacro

Macro AbstractPath : LeAbstractPath : EndMacro

Macro Graphics : LeGraphics : EndMacro

...

However the must appear after the LeInitialize() function.

 

Ok i'll add this to the header generator this evening when i come back from work

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

Another thing PureBasic doesn't have a line continuation symbol, so things like the multi-line arguments of Vec6, Vec9 and Vec16 have to be all on one line.

Intel Core i7 975 @ 3.33GHz, 6GB ram, GTX 560 Super OC, Windows 7 Pro 64bit

Link to comment
Share on other sites

Another thing PureBasic doesn't have a line continuation symbol, so things like the multi-line arguments of Vec6, Vec9 and Vec16 have to be all on one line.

 

I have uploaded the new header generator.

I did not prefix the constants with LE like Josh suggested because i'm not sure you want it.

If Purebasic #KEY_ESCAPE already exists then the value is probably also 27 so we could perhaps just comment it out ?

 

Unlike C++ header and Pascal Header i don't generate "function wrappers" in purebasic because i don't know how to. From what i have read in the manual Purebasic cannot return a structure as the result of a function, so this was a showstopper for me.

 

Anyway, functions are not so interresting (except if you want to traduce easily C++ code that uses them) because procedure performance is better.

With a procedure returning 1 result, you can use your variable n times after. But with a function you could be tempted to test n times the result of the function wich is slower. And even if you affect the function to a variable, you are still slower because the function creates a temporary variable to transmit the result while a procedure can do it directly.

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

I have uploaded the new header generator.

I did not prefix the constants with LE like Josh suggested because i'm not sure you want it.

If Purebasic #KEY_ESCAPE already exists then the value is probably also 27 so we could perhaps just comment it out ?

Never mind turns out PureBasic doesn't use them. I forgot to prefix the #.

 

Unlike C++ header and Pascal Header i don't generate "function wrappers" in purebasic because i don't know how to. From what i have read in the manual Purebasic cannot return a structure as the result of a function, so this was a showstopper for me.
Which version of the manual you have? 4.40 returns them fine.

 

Anyway, functions are not so interresting (except if you want to traduce easily C++ code that uses them) because procedure performance is better.

With a procedure returning 1 result, you can use your variable n times after. But with a function you could be tempted to test n times the result of the function wich is slower. And even if you affect the function to a variable, you are still slower because the function creates a temporary variable to transmit the result while a procedure can do it directly.

Sorry? A procedure is PureBasic's version of a function.

Intel Core i7 975 @ 3.33GHz, 6GB ram, GTX 560 Super OC, Windows 7 Pro 64bit

Link to comment
Share on other sites

Sorry? A procedure is PureBasic's version of a function.

LOL :D i don't speak purebasic, i mean functions and procedures like they are available in C++ and Pascal.

 

Can you provide me a sample ? lets say we have this C++function

function TVec16 GetThingMatrix (TThing athing , int atry)
{
TVec16 result;
leGetThingMatrix(athing, atry, &result);
return result;
}
end;

how would you traduce this to purebasic ? :(

 

 

PS: i have 4.30 manual

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

True you can't return typed structures from procedures, but you can return the pointer though there is no type safety then.

 

Procedure.i GetThingMatrix (*athing.TThing , atry.l)
Protected result.TVec16

leGetThingMatrix(*athing, atry, result)
ProcedureReturn result
EndProcedure

 

I really have no intention myself of using Leadwerks with PureBasic, as you can see PureBasic is too limited when dealing with 3rd party libraries. I'm doing this if anyone else wants to use PureBasic, though there really doesn't appear to be much interest.

Intel Core i7 975 @ 3.33GHz, 6GB ram, GTX 560 Super OC, Windows 7 Pro 64bit

Link to comment
Share on other sites

I really have no intention myself of using Leadwerks with PureBasic, as you can see PureBasic is too limited when dealing with 3rd party libraries. I'm doing this if anyone else wants to use PureBasic, though there really doesn't appear to be much interest.

 

I agree ... for some reason Josh was interrested in the project, and i like to fight for the desperate causes of the little, and also because i don't agree there should be one language to rule them all, one language to find them, one language to compile them all and in the darkness link them , so i did help with it ... but i don't really want to invest myself more alone in the void if a true user does not show up.

 

Delphi & object pascal is a bit different because i'm the user :huh:

 

So i think we will have a break and wait until someone comes :unsure:

 

Thank you Paul for the help, good luck with you'r game project (and good luck to me for my game because eventually i want to write a game too ;) )

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...