1. Are you planning to upload your awesome tool to Hive? Please review the rules here.
    July 9, 2018: The rules for the Tool Section have been revised. Please be sure to read the revisions.
    Dismiss Notice
  2. Seek unity between the elements in the 22nd Terraining Contest Poll.
    Dismiss Notice
  3. Seize the moment! The 18th Mini Mapping Contest has commenced.
    Dismiss Notice
  4. Gather 'round - the 20th Icon Contest Poll is out.
    Dismiss Notice
  5. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

cJass2Lua(v1.09) - Powerfull cJass and JASS converter

Submitted by Drulia
This bundle is marked as pending. It has not been reviewed by a staff member yet.
Description
Warcraft III Reforged brought us Lua scripting, but still a lot of map makers for WC3 are using JASS and cJass. JASS is because it's a standard and cJass just because C-style syntax rules. Unfortunately cJass extension is unsupported for Reforged and who knows how it will be. And JASS becomes deprecated. Lua is more efficient, useful and simple for game development. But a lot of projects are still on cJass/JASS and no way to convert them to Lua. Editor without cJass extension does not perceive this code. Re-writing code manually to Lua could take a lot of time, nobody wants to waste time on it. This tool comes to solve this problem. cjass2lua tool can easily convert cJass and JASS to readable Lua code, it will help you to upgrade your map by modern map development patterns.

Features
  • Analyzing and syntax checking cJass code
  • Full support of JASS/cJASS
  • Analyzing classes/structures and converting them to Lua meta table implementation with maximum compatibility
  • Producing .lua file with converted code of your cJass/JASS code
  • Advanced JASS features such as 'native', 'constant', 'type'
  • emmyDoc option for lua
  • Single file conversion
  • Smart string decection (constants, locals, globals, declared functions) and smart replacing string concatenation operator
  • Supports mixed code of cJass/JASS. It is fully recognizable.
  • Lambdas
  • Define macroses with expressions
  • Massive folder-to-folder conversion
  • Advanced logging of application
  • Opportunity to implement output for any other script language
  • 100% readable code formatting
  • Saving comments, comment positions and new lines, function and variable names, spaces in expressions
  • Config file with application's settings
  • Minimalistic and simple GUI interface
  • Command line interface
Unsupported features
  • Inheritance in structures
  • vJASS features as scopes, modules, etc. are unsupported (and have no sense in Lua)
  • Pre-processor directives
  • cJass 'for' loops are prohibited.
  • Macroses. Only constants and expression defines, function and variable shorters. Macroses are translated into global variables.
Pay attention to this before translating your code
  • Your code is 100% correct
  • Array indexes in Lua started from 1 in some cases. Just note that.
  • You have no objects or classes/structures
  • If structure has constructor (static creator) it must be named as create or new.
  • String concatecation operator + in JASS normally should be replaced with .. but string globals or functions defined beyond current file are unknown. And in this some cases with unknown in current context string globals or functions operator + will be not replaced.
  • Pre-increments or post-increments are supported and can be used in expressions, but for example a = i++ will be converted into a = (i + 1) and i will not be incremented. In this cases you need to increment it manually.
  • Read logs if something goes wrong, this application leaves cjass2lua.log file with all it's actions and possible problems. Everything should be fine if you have no warnings.

Example of translation:

Code (Text):
define {
    var1 = 245
    example = 2.46
}

define
    SOMETHING = 200
    EXAMPLE_STRING = "sfgsdfgsdfg"
    RAW_CODE = 'A0BX'
enddefine

globals
    int lel = 56;
    bool Illidan = false;
    //void NOTHING = NULL;
    string Arthas = "LichKing";
    player p = null;
    float value;
endglobals

int testMePlease(player p, unit u, bool flag)
{
    int integer1, integer2, integer3 = 35, integer4 = 21, wtf[], wtf35 = GetSuperMegaInt(a, b, c);
    local float pi = 3.14
    integer1 = someNotVisibleFunction.evaluate();
    int abilityCode = 'A0F2';
    string str = "Hello world!";

    timer t = CreateTimer()
    call TimerStart(t, 0.1, true, lambda void ()
    {
        timer t = GetExpiredTimer();
        int someComplicatedExpr = (integer1 / 2) * wtf35 + wtf[2] * g_Matrix[1][5] - FunctionOne(FunctionTwo(), arg25)
        SeparatedLinesCall(a, b,
        c
        , d, e, f);

        DestroyTimer(t);
    });
    //Comment 1

    if (a == b || b != 0)
    {
        Call1();
    }
    elseif(flag != 4.56)
    {
        Call2(); //Comment 2
    }
    else
    {
        int eee = 0;
        eee += wtf35;
        int i = 0;
        while (i < 25)
        {
            doSomething(a, b, i);
            i++;
        }
    }

    return integer24 * (call2(a / 3));
}
 

Code (Text):
var1 = 245
example = 2.46
SOMETHING = 200
EXAMPLE_STRING = "sfgsdfgsdfg"
RAW_CODE = 'A0BX'
lel = 56
Illidan = false
Arthas = "LichKing"
-- player p
-- float value


-- void NOTHING = NULL;
function testMePlease(p, u, flag)
    local integer3, integer4, wtf, wtf35, integer1, integer2 = 35, 21, {}, GetSuperMegaInt(a, b, c)
    local pi = 3.14
    integer1 = someNotVisibleFunction()
    local abilityCode = FourCC('A0F2')
    local str = "Hello world!"

    local t = CreateTimer()
    TimerStart(t, 0.1, true, function ()
        local t = GetExpiredTimer()
        local someComplicatedExpr = (integer1 / 2) * wtf35 + wtf[2] * g_Matrix[1][5] - FunctionOne(FunctionTwo(), arg25)
        SeparatedLinesCall(a, b,
        c
        , d, e, f)
 
        DestroyTimer(t)
    end)

    -- Comment 1
    if a == b or b ~= 0 then
        Call1()
    elseif flag ~= 4.56 then
        Call2()    -- Comment 2
    else
        local eee = 0
        eee = eee + wtf35
        local i = 0
        while i < 25 do
            doSomething(a, b, i)
            i = i + 1
        end
    end

    return integer24 * (call2(a / 3))
end
 


Source code and updates on github: fullmetal-a/cjass2lua
Contents

cJass2Lua - Powerfull cJass converter (Binary)

  1. yxq1122

    yxq1122

    Joined:
    Jun 5, 2018
    Messages:
    156
    Resources:
    1
    Tools:
    1
    Resources:
    1
    Sounds useful.
    I hope it could become more powerful, a general language converter that supports all war3 scripting languages such as (v)Jass, lua, cjass, wurst script, etc.
     
  2. Drulia

    Drulia

    Joined:
    Jan 16, 2013
    Messages:
    11
    Resources:
    0
    Resources:
    0
    Thanks. I added regular JASS syntax support, not you can convert both cJass and JASS and even mix their syntax in one file.
     
  3. Drulia

    Drulia

    Joined:
    Jan 16, 2013
    Messages:
    11
    Resources:
    0
    Resources:
    0
    Added support of vJASS structures
     
  4. Blarto

    Blarto

    Joined:
    Jan 17, 2010
    Messages:
    150
    Resources:
    1
    Spells:
    1
    Resources:
    1
    It might make sense to add a vanilla jass 2 lua converter, as vjass produces jass code at the end, that way you get around the difficulty of translating vjass/cjass artifacts, adding complete support to all styles of jass.

    Of course this conversion would mean projects would have to stay vjass/cjass/gui/jass if they choose this mode.
     
  5. ForgetJam

    ForgetJam

    Joined:
    Mar 9, 2020
    Messages:
    3
    Resources:
    0
    Resources:
    0
    nice job:pgrin:
     
  6. Macadamia

    Macadamia

    Joined:
    Jan 30, 2020
    Messages:
    876
    Resources:
    0
    Resources:
    0
    I tested this to convert a full Jass2 map to lua, and honestly, although very slow, it did an even better job at the conversion than the jass2lua integrated transpiler in Reforged WE.

    Fact is you can not call WE's transpiler on demand, so this is a great alternative.

    When converting a map from Jass 2 Lua, the manual method is a weeks process that can be very stressing because of total lack of type safety from Lua.

    Using this tool will only take a few minutes and save you from many nightmares !

    Rated 4/5, would definitely deserve 5/5 if the parsing was a bit faster.
     
    Last edited: May 6, 2020
  7. FatherofTime

    FatherofTime

    Joined:
    Jun 25, 2020
    Messages:
    1
    Resources:
    0
    Resources:
    0
    Didn't work for Tides of Blood N FINAL =/. There were a lot of problems in the compiler, given it is 5,500 lines of JASS. The conversion stopped around 5,000/5,550 lines of code and still had local variables, which returned errors. I am a total noob when it comes to JASS / LUA, but I thought I'd offer that feedback.

    The JASS script in TOB vN does NOT run in Reforged, but it did run in regular TFT. I thought converting it might solve the problem.
     
  8. Macadamia

    Macadamia

    Joined:
    Jan 30, 2020
    Messages:
    876
    Resources:
    0
    Resources:
    0
    Have your checked the unsupported features of this converter ? :

    Unsupported features
    • Inheritance in structures
    • vJASS features as scopes, modules, etc. are unsupported (and have no sense in Lua)
    • Pre-processor directives
    • cJass 'for' loops are prohibited.
    • Macroses. Only constants and expression defines, function and variable shorters. Macroses are translated into global variables.

    If you use any of this, it won't work properly.

    As for your map not working in Reforged, it is probably due to features that have been removed or rather bugs that have been fixed, rendering some workarounds or things exploiting such bugs to not work properly anymore.

    A map that does not work in Reforged cannot be made compatible with Reforged by just converting it from Jass to Lua scripting language.