3

I got code::blocks as my C/C++ compiler along with C++ for dummies, but my only problem is with a obscure scripting language that I have never heard of before; "Squirrel". Is it possible to change the scripting language of code::blocks to something more familiar to me, like lua?

Kamiccolo
  • 7,758
  • 3
  • 34
  • 47
  • Download the source for Code::Blocks, add Lua bindings, compile, run. – Captain Obvlious Sep 09 '13 at 22:11
  • I am not sure this will _exactly_ address your question, but I found a ***[three page conversation here](http://forums.codeblocks.org/index.php/topic,11873.0/wap2.html)*** that may be helpful – ryyker Sep 09 '13 at 22:59
  • 6
    just for the sake of information, code::blocks is an IDE, not the compiler :-) you are probably using gcc as your compiler – Natan Streppel Sep 09 '13 at 23:00
  • 2
    Regarding @HappyYellowFace's comment, ***very true, and commonly forgotten*** (one up'ed you for that). And leads to the observation that depending on the compiler you choose to use within C::B, just about any scripting language on the planet should work. – ryyker Sep 09 '13 at 23:04
  • @ryyker That post doesn't seem to have anything to do with changing the scripting language used in codeblocks – greatwolf Sep 09 '13 at 23:05
  • @greatwolf - Agreed. The referenced conversation ia about modifying C::B to more easily accept an external editor..., I was attempting to springboard off of what Captain O said about modifying the C::B source to add Lua bindings. But you are right, the connection was too weak. Thanks for pointing that out. – ryyker Sep 10 '13 at 15:35

1 Answers1

1

It seems doable in theory. Whether it is doable in practice, hard to say. Here is what you would need to do:

  1. create a folder src/sdk/scripting/lua in which you put the Lua interpreter (+ Lua libraries like io, math etc) source code and create project file for it
  2. create a folder in src/sdk/scripting/lua_bindings where you put your Lua bindings: the C++ files that allow Lua scripts access to the host application. I recommend you use a tool like SWIG to generate them (codeblocks uses SqPlus). This involves determining what code-blocks functions/classes you want to export, creating one or more .i files, running SWIG on them, put the generated files going into "lua_bindings"; create a DLL project for the bindings
  3. Create a src/lua_scripts in which you put the Lua equivalent of scripts found in src/scripts; or rather, a subset of those scripts, because it is unlikely you will want to export to Lua everything that is available via Squirrel if you're just following examples from a book
  4. Find where Squirrel interpreter is instantiated in codeblocks and where RegisterBindings is called; replace it with instantiation of a Lua interpreter and call your luaopen_codeblocks which you will have created via SWIG (no need for a RegisterLuaBindings if you use SWIG, it does that for you)
  5. Find where the various scripts are called by codeblocks (see http://wiki.codeblocks.org/index.php?title=Scripting_Code::Blocks). Call the equivalent Lua scripts (which are in lua_scripts -- you'll surely have to copy this to the installation folder for code-blocks). For example the startup.script, which is the Squirrel script that codeblocks automatically looks for at startup, is run by the following code in src/src/app.cpp:

    // run startup script
    try
    {
        wxString startup = ConfigManager::LocateDataFile(_T("startup.script"), sdScriptsUser | sdScriptsGlobal);
        if (!startup.IsEmpty())
            Manager::Get()->GetScriptingManager()->LoadScript(startup);
    }
    catch (SquirrelError& exception)
    {
        Manager::Get()->GetScriptingManager()->DisplayErrors(&exception);
    }
    

I think that's about it.

Naturally based on how extensive your scripting is, you may cut some corners, but as you can see, this is not for the faint of heart!

Oliver
  • 27,510
  • 9
  • 72
  • 103