Author Topic: Support for Interpreted Languages?  (Read 33104 times)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Support for Interpreted Languages?
« on: September 21, 2006, 10:58:46 pm »
I've seen some discussion on these boards re making projects wizards to support intepreted languages such as Matlab and R. Presumably, the same could also be done for more generic languages such as Python and Ruby. I'd hate to see Code::Blocks end up like Eclipse (a big, bloated, sluggish, memory hungry beast) but it would be very handy to be able to setup, edit and run interpreted language projects. Can the existing plugin framework handle this?

As an example, lets take my second favorite language Python (they're all my second favorites :D). I can open python files in the editor and seem to get basic code coloring, folding etc. (is this just default behavior of scintilla or something?) What I'd like to do is add a wizard for a python project. When the project is activated, c/c++ related elements of the GUI shoud be deactivated/hidden (e.g. compile etc.). However, I should be able to run the project in a console/new window and debug interactively (the latter would take some work, but could hook into Code::Blocks existing framework for debugging, such as tool bars. There should also be a dialog to enter Python specific configuration. So is all of this possible from within the current CB plugin framework??

cheers

(edited: title)
« Last Edit: September 22, 2006, 04:15:00 am by dmoore »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Projects for Interpreted Languages
« Reply #1 on: September 21, 2006, 11:33:37 pm »
In short, no.
There are plans to support (i.e. not just editing) languages other than C/C++, but it won't happen in the near future.
Be patient!
This bug will be fixed soon...

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Support for Interpreted Languages?
« Reply #2 on: September 22, 2006, 04:36:15 am »
So how about something a little simpler instead of offering full blown project support for interpreted languages. They are typically used as "glue" languages anyway, so the project infrastructure is usually unecessary.

Playing around in code::blocks I notice that it is possible to add groupings for different sources, allowing those sources to be added to any project and kept separate from everything else. So I'm thinking that I could write a plugin that adds a "Python", "Ruby" or, more generically, a "Scripting" menu that has (initially) a few options

* Config: setup location of interpreter, specify environment variables, command line options etc. [persistent]
* Current Interpreter Target: presents user with a list of the relevant sources as a possible run target. Allows additional environment variables, command line options. [save this target specific info in a target config file]
* Run Target: executes the target in a new window (asks user to save etc. first)
* Run Interpreter: run the interpreter in a new window

I have no experience with the CB plugin framework, but have written a variety of GUI bits and pieces in the past and have been looking at the source for some of the current CB plugins. I have a lot on my plate at the moment, so if someone wants to jump in first with this or something better, be my guest.
« Last Edit: September 22, 2006, 04:37:50 am by dmoore »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Support for Interpreted Languages?
« Reply #3 on: September 22, 2006, 08:23:10 am »
What you 're describing is trivial to do with a very simple plugin. So simple that might even serve as a plugin tutorial that actually does something more than greeting the world ;).
Be patient!
This bug will be fixed soon...

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Support for Interpreted Languages?
« Reply #4 on: September 22, 2006, 12:51:56 pm »
...and so I decided to write this tutorial. Hopefully it will help many would-be-plugin-developers :)

Work in progress: http://wiki.codeblocks.org/index.php?title=Creating_a_plugin_that_actually_does_something
Be patient!
This bug will be fixed soon...

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Support for Interpreted Languages?
« Reply #5 on: September 22, 2006, 02:40:32 pm »
you, sir, are a great man :D
I look forward to the conclusion of the wiki entry. I'll use that code as a template for adding some more integrated language support when you're done. (at a minimum I want to add debugging support, which is certainly a less trivial task, requires language specific coding and more hooks into CB)

BTW where do i get the latest version of the SDK? I could only find the RC2 SDK, but in the Sep 20 recent nightly builds the entry says several things about about plugins changing...

cheers

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Support for Interpreted Languages?
« Reply #6 on: September 22, 2006, 03:04:30 pm »
BTW where do i get the latest version of the SDK? I could only find the RC2 SDK, but in the Sep 20 recent nightly builds the entry says several things about about plugins changing...

Obviously, we can't distribute the SDK of the development version as a package because it is changing. To build a plugin for the development version, your only option is to first build the development version yourself. It's not hard and it takes less than 30 minutes (including building wxWidgets).
For more info, check Installing Code::Blocks from source on Windows (sorry if I guessed your platform wrong :)).
Be patient!
This bug will be fixed soon...

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Support for Interpreted Languages?
« Reply #7 on: September 22, 2006, 03:20:44 pm »
my apologies. I downloaded the source yesterday, but didn't look for the latest version of the SDK in the most natural place...  :oops:
don't worry, I have no particular aversion to compiling source (boost libraries and wxwidgets yesterday). I assume your wiki entry will be based off the latest version of the SDK then?

(and windows is correct. I think I must write like a windows person. I tried Ubuntu recently and it looks very interesting)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Support for Interpreted Languages?
« Reply #8 on: September 22, 2006, 10:30:52 pm »
I comiled a working version of CB from the nightly builds. Unfortunately, it looks like I have a build (19th or 20th sep) whose plugin wizard produce code that's incompatible with the latest version of the sdk. When I try to compile the template code generated by the wiz, it doesn't understand any of the preprocessor functions (I'm assuming they're preprocessor functions) such as

Code: [Select]
CB_DECLARE_PLUGIN();
I assume if I wait a day or two I will be able to download a nightly build with a compatible wizard?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Support for Interpreted Languages?
« Reply #9 on: September 23, 2006, 12:15:37 am »
This was fixed earlier today (revision 2988).
Be patient!
This bug will be fixed soon...

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Support for Interpreted Languages?
« Reply #10 on: September 29, 2006, 07:33:35 pm »
ok, I managed to get a very simple plugin to work that creates an "Interpreters" menu with a few options and adds a context menu item for right clicks on the project tree to execute relevant scripts (I only add this item to the context menu if the file extension matches a known type). So far I only have it setup to handle python files, but it will be easy to add support for any interpreter. I'm using wxExecute to run the interpreter.

Before I really jump into the deep end and work on debug support (more questions on that later) I have two quick questions:
1. is there away to register file type classes from the plugin? it's easy to do manually through the menus: Project -> Project Tree -> Edit file types & categories or the Project Tree context menu, but i may as well automate this if possible
2. Is there a standard format for plugin settings and configuration files? Where are they stored? I want to store the list of interpreters, paths, command strings etc.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Support for Interpreted Languages?
« Reply #11 on: September 29, 2006, 09:36:16 pm »
Quote
1. is there away to register file type classes from the plugin?

Unfortunately, not yet.

Quote
2. Is there a standard format for plugin settings and configuration files? Where are they stored? I want to store the list of interpreters, paths, command strings etc.

ConfigManager comes to the rescue ;).

Code: C++
  1. ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("your_plugin_name"));
  2. cfg->Write(_T("/any/kind/of/path"), some_string);
  3. cfg->Write(_T("/paths/are/not/filesystem/paths"), some_float);
  4. cfg->Write(_T("/paths/are/just/a/way/for/you/to/organize/data"), some_bool);
  5.  
  6. some_string = cfg->Read(_T("/another/path"), a_default_string_if_the_key_doesnt_exist);
  7. some_int = cfg->ReadInt(_T("/always/start/the/paths/with/a/slash"), a default_int);
  8.  
  9. ...and so on and so forth...
  10.  

For more info, check ConfigManager's documentation and, as always, consult the other plugins' sources :).
Be patient!
This bug will be fixed soon...

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Support for Interpreted Languages?
« Reply #12 on: September 29, 2006, 11:10:35 pm »
thanks! more soon.

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Support for Interpreted Languages?
« Reply #13 on: September 30, 2006, 10:30:48 pm »
I am sure you aware of PyDev but perhaps you could port over the Java based python debugger for use in Code::Blocks.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Support for Interpreted Languages?
« Reply #14 on: October 04, 2006, 07:25:22 pm »
I am sure you aware of PyDev but perhaps you could port over the Java based python debugger for use in Code::Blocks.

Yes, I use PyDev and its pretty darn good. However, I don't think I want to go down that path (seems like I would have to know too much about Java libraries and the Eclipse SDK - no thanks). My current plan is to pass commands to the internal debuggers provided by most interpreted languages by rerouting std in/out. it should be possible to set up REGEX commands to obtain the current code position etc (I know I can do this for python and, probably, ruby). Ideally the user would setup a debug config file that contains the definitions required to pass commands to the debugger and interpret its output. If someone has better ideas I'm all ears.

Anyway, here is the code for the interpreters plugin to date. I used the data specification for the interpreters that Mandrav provided in the Wiki. There's some ugliness in the code and UI that I will eventually clean up. (blame it on unfamiliarity with wxWidgets)

Features:
add & edit interpreters + associated actions in the environment settings dialog (I'm using the build icon). (these are stored persistently)
Interpreters menu: run interpreter actions on a file target (selected using a file dialog - currently uses a "*.*" wildcard extension instead of the correct one)
Project Tree Context menu: run interpreter actions on selected file (obviously you have to add your file to the project first)

Feedback appreciated.

EDIT: Plugin removed - reposted on next page.
« Last Edit: October 05, 2006, 05:13:19 am by dmoore »