How do I access functions within a host application?

Started by Velatus, May 03, 2011, 06:13:27 AM

Previous topic - Next topic

Velatus

Hi everyone!

Since this is my first post, let me introduce myself. My (real) name is Guillaume Rangheard. I'm a french student in architecture, and a freelance web developer (mostly in JS). I'm currently working on a turn-based strategy game project, loosely based on Battle For Wesnoth and Vantage Master. I plan to use newLISP as a scripting language for my engine.

Is there any way I could access my engine's functions directly from the newLISP interpreter? (The engine is in FreeBASIC.) If impossible, is there a workaround?

Thanks in advance.



V.

HPW

#1
Hello Guillaume,



wellcome on the board.



Do you plan to do the mainloop in FreeBASIC and call function in newLISP?

Which OS are you using? Windows?



Then you should check if FreeBASIC does support the import of DLL-functions.

If so, you can use the DLL-flavour of newLISP and import the "newlispEvalStr" function.

When you want to call function inside Freebasic from newLISP it depends if freebasic can export its functions via DLL-calling conventions. The you can import them in newLISP.



Regards



Hans-Peter
Hans-Peter

Velatus

#2
Sorry for the lack of precision. The program is developed on Windows. FreeBASIC is able to import functions from a DLL with ease. Actually, someone on the FB forum has already writen a header for NewLISP. Regarding whether or not FB can export functions, I don't know what to say. As a matter of fact, with a few additional keywords in a function declaration, and the toggling of an option at compile time, FB is able to compile DLL's. What I don't know is if one can export functions from an EXE -- as my engine is an EXE.

HPW

#3
This older similar discussion maybe of interest for you with a sample code in delphi:



http://newlispfanclub.alh.net/forum/viewtopic.php?t=2387&highlight=">http://newlispfanclub.alh.net/forum/vie ... highlight=">http://newlispfanclub.alh.net/forum/viewtopic.php?t=2387&highlight=



There uses the main-exe a newlisp.dll and allow a callback into the main-app.
Hans-Peter

Velatus

#4
Thanks very much HP. You're my new hero. I think I sort of figured it out. I'll start coding tomorrow when i'm off work (it's 2 pm here in France). It seems that with some hackery, you can get newLISP to call a function from an FB exe. BTW, which calling convention does newLISP use? (FreeBASIC supports cdecl, stdcall and pascal.)

(Oh and did I say thank you?)

Velatus

#5
Oh well don't bother answering my question: I googled (lazy bastard me...). It will be stdcall then.

HPW

#6
Glad you have an idea for your problem.

When you get something working, it would be nice to post a skeleton/template here on the forum.

Then other interested people may have a easier start.

And newLISP has one more working language binding. More is better!



;-)



PS: Which GUI do you use under FreeBasic? WinAPI or GTK or ?
Hans-Peter

Velatus

#7
I'll post a template as soon as I get something working. Promise. :)

Actually I don't use any GUI, save a couple of calls to the win32 API in order to get the user's screen resolution (ya know, that GetSystemMetrics thing). The rest is all done in FB, which has its own built-in gfx library. The game is fullscreen, as you might have guessed, and only has very few actual GUI elements to it, which I'm implementing by hand.