Author Topic: Codeblocks ported to sqrat  (Read 34080 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Codeblocks ported to sqrat
« on: February 12, 2014, 02:43:22 pm »
Hi folks,
i finally managed to finalize the “pre alpha” release of the codeblocks port of sqrat.
With “pre alpha” I mean: it should be usable, and all scripts that worked with the old implementation should also work with this one (with some work, see more down).
The code can be found here: https://github.com/bluehazzard/codeblocks_sf

What is new:
* Use sqrat instead of sqplus
why?
Sqplus isn't maintained since a wile now. My initial intention was to port some more wxWidgets stuff to c::b, but the lack of features from sqplus (different ctors etc.) obstruct this. So I decided to try to port c::b  to sqrat.
Advantages?
- Maintained and developed in the future
- Different Ctors for classes (no  copy, copy only etc.)
- Easy parameter specialization
- Relative easy interface

* Use squirrel 3.X.X

What is the difference from the user site:
Script:
1) Squirrel scripts can now use native strings and wxStrings. No need of _T() or wxT
2) Squirrel scripts use now UTF8 and have a “full” unicode support
3) Constants are now really constants and not some obscure get functions
4) Many new functions (and more will follow)
5) The API is broken  :'(. This is a consequence of squirrel 3.X.X and 3) but not as serious as it might appear, because it exists a convert plugin that (hopefully) can resolve all breaks.

Main GUI site

1) Error handling is now centralized and has a uniform layout
2) Errors are way more informative
3) The sdk interface to the script is more intuitive
4) It is prepared to use multiple vm
5) A test suite for the squirrel binding

More about the API break and how to resolve it:
In squirrel 3.X “base” is a new keyword, so it can't be used as variable name anymore.
The constants (ex. PLATFORM, PLUGIN_SDK_VERSION_MAJOR) are now real constants and not get functions from the RootTable. So thy can't be accessed anymore with “::PLATFORM”. The “::” isn't necessary anymore. So now you have to use “PLATFORM”. Why does I broke this? In the old binding you could change this const values (ex “EXECUTABLE_EXT = _(“blabla”) ”). this is not intended. Now constants are real squirrel strings and replaced at compile time.
How do use my old scripts? Simply:
1) open the scripting console
2) open the src/scripts/ConvertOldToNewScript.script
3) run Plugins/Convert Scripts
4) select the scripts you want to convert (multiple files should work)
5) the plugin should now convert all constants to the right name and replace “base” with “_base”

The main work should be done. But I need some help for a few things:
1) Code style and naming conventions: I have added new classes and files and don't know if the names are acceptable.
2) Testing!!! I don't have many scripts available, so I could not test the full interface.
3) Some look over sq_wx_type_handler.h. Im not fully happy with the Var<const wxString&> implementation
4) Memory leaks. I hope I don't have introduced some leaks .
5) wx3.0 and x64 support ( I will upload the project files later).
6) Documentation: I have tried to implement some documentation with doxygen, but it isn't  pretty nor complete. Has someone an idea how to improve it, or make it more readable.
7) Git. The branche is not in sync with the main branch. From quite a long time now. Can someone tell me how I can easily resync with the main branch, without 1000 conflicts...

greetings

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Codeblocks ported to sqrat
« Reply #1 on: February 12, 2014, 02:53:06 pm »
I haven't look into your source code(I'm not familiar with either sqrat nor sqplus), but from what your post wrote, it was excellent work! Many thanks.

Quote
7) Git. The branche is not in sync with the main branch. From quite a long time now. Can someone tell me how I can easily resync with the main branch, without 1000 conflicts...
Git rebase onto the current C::B head? So patches will apply one by one.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Codeblocks ported to sqrat
« Reply #2 on: February 12, 2014, 08:18:09 pm »
Its very interesting, indeed - however, I am not a GIT user and merging the changes into SVN manually is really hard (I tried, but gave up meanwhile ::)). You should try what ollydbg said and try re-base your copy, so that it is in sync with trunk and we can easily create a patch or alike. If you manage, you can do this more regularly from there on.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Codeblocks ported to sqrat
« Reply #3 on: February 13, 2014, 12:39:04 am »
Morten: It is time to try it, then you won't look back to svn again, I promise:) BTW, I think github allows you to download the head of some branch as an archive (Download as ZIP button)
BlueHazzard: svn doesn't handle git merges, so you have to have linear history. Also it is good to do a cleanup of commit messages and some useless commits you have. See this for an overview of git rebase -i   http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

Otherwise pretty good job. What OSes have you tested this?

7) Git. The branche is not in sync with the main branch. From quite a long time now. Can someone tell me how I can easily resync with the main branch, without 1000 conflicts...
Unfortunately you'll have to fix the conflicts once more time and you'll have to refix the old conflicts you've already fixed, but after you fix them then won't show up again.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Codeblocks ported to sqrat
« Reply #4 on: February 13, 2014, 12:46:47 am »
It seems that you haven't fixed the autotools build system, the -unix.cbp project file is similarly broken.
Do you have any plans to do it?

Edit: Ignore the part with the -unix.cbp. It turned out that I was using old code.
« Last Edit: February 13, 2014, 08:48:53 am by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Codeblocks ported to sqrat
« Reply #5 on: February 13, 2014, 06:26:38 am »
Just for the record: you can use a github repo with git (obviously) and svn (https://help.github.com/articles/support-for-subversion-clients).

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: AW: Re: Codeblocks ported to sqrat
« Reply #6 on: February 13, 2014, 07:11:40 am »
Just for the record: you can use a github repo with git (obviously) and svn (https://help.github.com/articles/support-for-subversion-clients).
Yes, I know about this and already using it. Still, it does not help to merge trunk into this repo to be up to date again. :-/


Just for the record: you can use a github repo with git (obviously) and svn (https://help.github.com/articles/support-for-subversion-clients).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Codeblocks ported to sqrat
« Reply #7 on: February 14, 2014, 02:29:33 am »
I made now a rebase and pushed it to github. I don't know if this was a good decision (because of the rewriting of the history...)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Codeblocks ported to sqrat
« Reply #8 on: February 14, 2014, 10:25:35 am »
Don't worry too much about it. And keep in mind that the history will be re-written anyway when these changes land in trunk (git svn dcommit will make sure to execute git svn rebase)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Codeblocks ported to sqrat
« Reply #9 on: February 21, 2014, 12:26:38 pm »
I have now created a separate script plugin class and manage all events from there.
I added the possibility to use c::b events in scripts.

I had some difficulties with the menu events not getting handled. But after updating my compiler from 4.7 to 4.8 all works. I don't know if this had do do with a "hard" rebuild, or with the compiler version.
Can please someone test this build with a different compiler then 4.8.1 and look if the menu and c::b events work? Of course all others are also invited to test...

procedure to test:
Code
1)   Compile all
2)   Run C::B sqrat port
3)   Open scripting console
4)   In the script console open "scripts\test\script-test-plugin.script"
5)   Run Menu->Plugins->Test scripting
6)   Check scripting console for output (The Volume test fails)
7)   In the script console open "scripts\test\event-test-plugin.script"
8)   Run Menu->Plugins->Test Event scripting
9)   Open and close random project and files -> Check in the console for errors
10) Reload a plugin (repeat step 4->9 or 7->9)
thank you

greetings
« Last Edit: February 21, 2014, 12:30:30 pm by BlueHazzard »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Codeblocks ported to sqrat
« Reply #10 on: March 21, 2014, 10:18:59 pm »
Hi!
i have found a bug. A very strange bug. Can please someone review this code, if it is right:
Code
template<>
struct Var<const wxString&> {
    const wxString& value;
    wxString tmp_value;
    Var(HSQUIRRELVM v, SQInteger idx) : value(tmp_value){
        if (!Sqrat::Error::Instance().Occurred(v)) {
            wxString* ptr = ClassType<wxString>::GetInstance(v, idx);
            if (ptr != NULL) {
                tmp_value.Append((*ptr).c_str());
            } else {
                Sqrat::Error::Instance().Clear(v);
                const SQChar* str;
                sq_tostring(v, idx);
                sq_getstring(v, -1, &str);
                tmp_value = wxString::FromUTF8(str);
                sq_pop(v, 1);
            }
        }
    }
    static void push(HSQUIRRELVM v, const wxString& value) {
        ClassType<wxString>::PushInstanceCopy(v, value);
    }
};
i need the member value to be a const ref to a wxString.

On linux this code works without problems on windows it worked with gcc 4.7 but with 4.8 the value overwrites some other variables in the code.
You can reproduce it with this steps:
Code
1. Compile c::b from my git hub repo
2. Set breakpoint at "include/scripting/sqrat/sqrat/sqratGlobalMethodes.h" at line 184 and 185
3. Start the debugger
4. load the script "scripts/ConvertOldToNewScript.script"
5. run the script from menu plugins->Convert Scripts
5b. if a messagebox pops up press ok
6. The debugger will now stop on breakpoint 1: Look at the variable "method". It will hold the right address for the function "wx_GetFileFromUser"
7. Continue the debugger one line, it will stop on breakpoint 2
8. The pointer "method" does not point anymore to a valid function....

after investigating i found the error in the source posted previously. The address gets changed at the initialization of the reference in the first line of the constructor...

i have no clue why, or how i should fix this, because for me the code looks ugly but right...

greetings

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Codeblocks ported to sqrat
« Reply #11 on: March 22, 2014, 12:14:53 am »
Why do you need tmp_value and value? This seems quite odd.
You have to talk to a c++ expert but I suppose the value(tmp_value) initialization is an undefined behaviour, because the members are initialized in the order they are declared, not the order you use them in the initializer list. So you're initializing value to be a reference to uninitialized object.

If you can reorder the members, you could try it.

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Codeblocks ported to sqrat
« Reply #12 on: March 22, 2014, 03:55:56 pm »
i tried it, but now it crashes in on a other place, and i haven't discovered yet where....
funny....

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Codeblocks ported to sqrat
« Reply #13 on: March 22, 2014, 04:39:52 pm »
Do you know why you need the reference?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Codeblocks ported to sqrat
« Reply #14 on: March 25, 2014, 08:55:50 pm »
I have fixed the error. It was interesting: When i debugged the source, it jumped in the right specialized template function, but if i printed the value type outside specialized  the function it showed me the wrong type. On the end i had to include the header file to the right places... it is pretty tricky to find such a error, without compiler warning, and also the right programflow, but perhaps with a wrong value interpretation...

still waiting for test results with bigger script plugins ;)

new added:
  • wxBell
  • wxDirSelector
  • wxMessageBox

greetings