Author Topic: CodeBlocks Scripting abilities  (Read 6527 times)

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
CodeBlocks Scripting abilities
« on: January 27, 2006, 06:50:09 pm »
today i played a little with (angel-)scripts

in this thread i'll post from time to time some interesting scripts,
which should demonstrate specific details how to access CodeBlocks internals from scripts.

everybody who discovers interesting details is invited to post his scripts here too
(with some comments please, if the code isn't obvious)

for the start, my todays favorite "tiwag1.script"

Code
//
// test scripting of CodeBlocks
//

const wxString scriptname = "tiwag1.script";

int main()
{
    wxString msg;
    int msgtype = scICON_INFORMATION;

    msg = "running " + scriptname;
    //Log() messages are going into "Code::Blocks Debug" tab
    Log(msg); 

    msg = "trying to get Editor";
    Log(msg);

    Editor@ ed = EditorManager.GetBuiltinActiveEditor();
    if ( ed == null )
    {  //all editors closed at the moment
        msg = "ERROR: got no active editor";
        msgtype = scICON_ERROR;
    }
    else
    {
        msg = "trying to get Editors FileName";
        Log(msg);

        msg = "SUCCESS: active editors FileName: ";
        msg += "\"";
        msg += ed.GetFilename();
        msg += "\"";
    }

    Log(msg);
    Message(msg,scriptname,msgtype);

    return 0;
}



Happy scripting !

takeshimiya

  • Guest
Re: CodeBlocks Scripting abilities
« Reply #1 on: January 27, 2006, 07:07:12 pm »
Seems pretty easy and powerful. :D

Questions:
1) What on earth is that @?
I guess there isn't any need to use memory allocations/pointers/references.

2) Those wxString needs _T() wrappers to work in unicode mode, right?

3) What can be exposed from wxWidgets? Everything? only wxString?
It would be great if one could create some simple interfaces with XRC+AngelScript.

I'm thinking in a part of Code::Blocks that it will be useful: the New Project dialogs.
As is now, if you want to create some wizards, you need to do it with a plugin, like wxSmith does right now.
But that is not-so-great, because if you want to create let's say a SDL application, it seems an overkill to create a plugin only for that.

Would be something at least simmilar to this be possible with XRC+AngelScript?

« Last Edit: January 27, 2006, 07:57:36 pm by Takeshi Miya »

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: CodeBlocks Scripting abilities
« Reply #2 on: January 27, 2006, 07:08:38 pm »
most of the answers you'll find in "sdk/as/bindings/scriptbindings.cpp"

[edit] post a patch when you got XRC working with as ;-)
« Last Edit: January 27, 2006, 07:11:08 pm by tiwag »

takeshimiya

  • Guest
Re: CodeBlocks Scripting abilities
« Reply #3 on: January 27, 2006, 07:11:20 pm »
most of the answers you'll find in "sdk/as/bindings/scriptbindings.cpp"

Sorry, but those are the current bindings, which doesn't answers my questions, please read :P

post a patch when you got XRC working with as ;-)
I don't think it's even possible to do that with AngelScript, that's why I'm asking here :)
« Last Edit: January 27, 2006, 07:13:00 pm by Takeshi Miya »

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: CodeBlocks Scripting abilities
« Reply #4 on: January 27, 2006, 07:14:52 pm »
most of the answers you'll find in "sdk/as/bindings/scriptbindings.cpp"
Sorry, but those are the current bindings, which doesn't answers my questions, please read :P
what else than the current bindings do you expect to be working ? ;-)

takeshimiya

  • Guest
Re: CodeBlocks Scripting abilities
« Reply #5 on: January 27, 2006, 07:20:51 pm »
most of the answers you'll find in "sdk/as/bindings/scriptbindings.cpp"
Sorry, but those are the current bindings, which doesn't answers my questions, please read :P
what else than the current bindings do you expect to be working ? ;-)

Let's see, my questions aren't about the bindings (which as you've said are in as/bindings).
I've asked other questions (see again, I'm writting them in red).

See here: http://forums.codeblocks.org/index.php?topic=2168.msg17067#msg17067
(I've created an infinite-loop :lol:)
« Last Edit: January 27, 2006, 07:22:43 pm by Takeshi Miya »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: CodeBlocks Scripting abilities
« Reply #6 on: January 27, 2006, 07:24:25 pm »
Quote
-What on earth is that @?
It's a "handle". Handles are reference counted objects.
If it helps you understand it better, think of it as a pointer (it's not, but valid statement in C::B).

Quote
-Those wxString needs _T() wrappers to work in unicode mode, right?
_T() does not exist in scripts.

Quote
-What is exposed from wxWidgets? Everything? only wxString?
Whatever we expose ;)
Currently I 've exposed wxString and wxArrayString. Note that I 've only exposed part of them, not fully.

Quote
Would be something at least simmilar to this be possible with XRC+AngelScript?
I had created a scripted wizard which would work entirely off scripts and XRC. You know: "Next", "Previous", "Finish" etc.
I guess I could post it as a sample...
Be patient!
This bug will be fixed soon...

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: CodeBlocks Scripting abilities
« Reply #7 on: January 27, 2006, 07:39:20 pm »
ok

then PLEASE look in all files of sdk/as/bindings/*.cpp;*.h   ;-)

seriously, take a look in these files and try to understand it,
when you have a specific problem with the usage of these commands, then post it here,

if you look specifically for the GetBuiltinActiveEditor() method,
you see in the scriptbindings.cpp the following registering for it
    engine->RegisterObjectMethod("EditorManagerClass", "Editor@ GetBuiltinActiveEditor()", asMETHOD(EditorManager, GetBuiltinActiveEditor), asCALL_THISCALL);


as far as i understand it, the @ is obviously part of the declared typename,
used to tell the as-engine, that a custom data object of type "Editor@" is used as returnvalue.

therefore we declare a Editor@ type in order to match the definition for the method GetBuiltinActiveEditor()
it is nothing fancy, PLEASE just take a moment to look in the files i told you
(and i got told to look into from Yiannis ;-) ) 
how it works.

takeshimiya

  • Guest
Re: CodeBlocks Scripting abilities
« Reply #8 on: January 27, 2006, 08:05:11 pm »
Ok, I've answered myself 2)...

Code
Editor@ type in order to match the definition for the method GetBuiltinActiveEditor()
Yes, I can see that it matchs the definition... but it doesn't answers why an @ is requiered (both from the binder viewpoint and the scripter viewpoint)...

As for 3), maybe you misunderstood, but I'm NOT asking what can be done with the current bindings, instead, I'm asking what bindings could be added in the SDK without much pain.
I know that the current bindings are wxString, wxStringArray, and the MessageBox's, but it's not what I'm asking.

I really don't know if it would be doable to create wxWidgets widget bindings to create dialogs.
But I guess it would be a very difficult task to do that, anyways...