• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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

  • Like
Reactions: AGD and Vinz
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:
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:
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)

Reviews
eejin
It managed to convert some simple Jass maps and so can be very useful for when you are moving to Lua. having vJass support would be a big plus, but the current featureset is already quite useful. Approved!
Level 6
Joined
Jan 17, 2010
Messages
149
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.
 
Level 12
Joined
Jan 30, 2020
Messages
875
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:
Level 1
Joined
Jun 25, 2020
Messages
1
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.
 
Level 12
Joined
Jan 30, 2020
Messages
875
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.
 

eejin

Tool Moderator
Level 12
Joined
Mar 6, 2017
Messages
221
It managed to convert some simple Jass maps and so can be very useful for when you are moving to Lua. having vJass support would be a big plus, but the current featureset is already quite useful. Approved!
 
Top