Thread: Free scripting library?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Location
    Melbourne, Australia
    Posts
    92

    Unhappy Free scripting library?

    Hi...
    I'm making an app that needs some sort of scripting support so the user can write their own custom scripts for it.

    Does anybody know of a good scripting library, preferably using a C/C++ style language (if not C/C++ please tell me anyway, its just that C/C++ style is my personal favourite ) that would be possible to use under windows with MSVC++6?

    Thanks,
    Jeff

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: Free scripting library?

    Originally posted by PsychoBrat
    Hi...
    I'm making an app that needs some sort of scripting support so the user can write their own custom scripts for it.

    Does anybody know of a good scripting library, preferably using a C/C++ style language (if not C/C++ please tell me anyway, its just that C/C++ style is my personal favourite ) that would be possible to use under windows with MSVC++6?

    Thanks,
    Jeff
    I do shell scripting under Windows with JScript.....its like JavaScript and uses Windows Scripting Host...it can access ActiveX too...

    Save this as a text file and call it "test.js"...then double click;

    Code:
    try{
    	var objDate = new Date;
    	var objStr = "Date is ";
    	objStr += objDate.getDate();
    	objStr += "/";
    	objStr += objDate.getMonth() +1;
    	objStr += "/";
    	objStr += objDate.getYear();
    	WScript.Echo(objStr);
    	objStr = "";
    	objDate = "";
    
    }
    catch(e){
    	WScript.Echo("Error running script!!");
    	WScript.Quit(1);
    }

  3. #3
    Registered User
    Join Date
    Aug 2001
    Location
    Melbourne, Australia
    Posts
    92
    but how could I use this in my app... and share certain variables/functions in my app for the user to call in his/her scripts?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by PsychoBrat
    but how could I use this in my app... and share certain variables/functions in my app for the user to call in his/her scripts?
    That's where it gets nasty....usually the old way to share info with scripts is by the return value from main......not very decent info!!

    These scripts as I said can use COM.....so if you want to share data between scripts, you should look at using a COM object to interface between your app and the script...

    I do very little COM, but when I do I use ATL (comes with VC++6 and is like an MFC for COM). You use this tool to create a dll and add classes to it that your script can communicate with / pass data / recieve data...etc. Also, its a bit more difficult to get COM to work with scripts (as it uses a special interface called a dispatch interface) but ATL does all the work for you

    Its a lot of work to understand and needs some reading on your part.....but to give you a taste, here's a basic COM object I wrote this morning to give the same functionality as my above script (I have attached the VC++ project files. Open the PoorDate.dsw file to open VC++ and click build. The dll produced houses the COM object).

    When the dll is build, go to the debug dir (where you will find the actual dll) and save the following as Reg.bat

    Code:
    regsvr32 poordate.dll
    Now double click the file and windows will register your dll to be used as a com object on the system.

    Now create the following script as Test.js (like my previous one - but more personal!).

    Code:
    try{
    	var objDate = WScript.CreateObject("PoorDate.FordyDate.1");
    	var objStr = "Date is ";
    	objStr += objDate.GetDay();
    	objStr += "/";
    	objStr += objDate.GetMonth();
    	objStr += "/";
    	objStr += objDate.GetYear();
    	WScript.Echo(objStr);
    	objStr = "";
    	objDate = "";
    
    }
    catch(e){
    	WScript.Echo("Error running script!!");
    	WScript.Quit(1);
    }
    Now run it and it should run as my first script, but using my ATL created COM object !

    When your finished, change the bat file to

    Code:
    regsvr32 /u poordate.dll
    and run it. This clears the registration of the dll and keeps things tidy

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lots of freeware
    By major_small in forum General Discussions
    Replies: 60
    Last Post: 02-14-2017, 03:00 AM
  2. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  3. Program that displays amount of free memory
    By trancedeejay in forum Linux Programming
    Replies: 3
    Last Post: 01-13-2006, 01:27 PM
  4. Replies: 19
    Last Post: 01-12-2006, 11:04 AM
  5. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM