Created
August 24, 2015 11:39
-
-
Save jamesu/f24731bb39d25d80b68a to your computer and use it in GitHub Desktop.
TS Lua Conversion Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ******** | |
TorqueScript code | |
// ******** | |
$shit = 1; | |
$fudge = 2 + 2.3; | |
if ($fudge < 2) // TOFIX | |
{ | |
$shit = 2; | |
} | |
else | |
{ | |
$shit = 3; | |
} | |
$poof = 123; | |
$err = 456 + 789; | |
$fudge = 12 & 0x100; | |
$fudge[0] = 0; | |
%local = "value"; | |
/// Docblock here | |
new TestObject(err, 1, 2, 3) | |
{ | |
field1 = "123"; | |
arrayField[0] = "456"; | |
importedLocal = %local; | |
new Juice(y) | |
{ | |
fresh = true; | |
new Melon() | |
{ | |
}; | |
new Bannana() | |
{ | |
}; | |
}; | |
new Tea() | |
{ | |
}; | |
}; | |
%candy[0] = 123; | |
%candy[$poof] = 456; | |
%candy[$poof, 0] = 567; | |
for (%i=0; %i<5; %i++) | |
{ | |
debugTimer(false); | |
%count = 0; | |
for (%j=0; %j<1000000;%j++){//1000000; %j++) { | |
//%value = 999999; | |
%value = 999999 + 10101010; | |
%count += %value; | |
simpleCounter(false); | |
} | |
simpleCounter(true); | |
debugTimer(true); | |
} | |
function foo(%err) | |
{ | |
return 123; | |
} | |
echo(foo()); | |
// ******** | |
// Generated lua equivalent code | |
// ******** | |
local _local | |
local _candy = {} | |
local _i | |
local _count | |
local _j | |
local _value | |
_G['$shit'] = 1 | |
_G['$fudge'] = (2.29999995) + (2) | |
if ((_G['$fudge']<2)) then | |
_G['$shit'] = 2 | |
else | |
_G['$shit'] = 3 | |
end | |
_G['$poof'] = 123 | |
_G['$err'] = (789) + (456) | |
_G['$fudge'] = __BAD((12),(256)) | |
_G['$fudge'][0] = 0 | |
_local = 'value' | |
-- Docblock here | |
(function(_local) | |
local __OBJ_SUB | |
local __OBJ_SUB_SUB | |
__NOBJ = createObject('TestObject', 1, 2, 3) | |
__NOBJ.field1 = '123' | |
__NOBJ.arrayField[0] = '456' | |
__NOBJ.registerObject('err') | |
__OBJ_SUB = __NOBJ | |
__NOBJ = createObject('Juice') | |
__NOBJ.fresh = 1 | |
__NOBJ.importedLocal = _local | |
__NOBJ.registerSubObject('y') | |
__OBJ_SUB_SUB = __NOBJ | |
__NOBJ = createObject('Melon') | |
__NOBJ.registerSubObject('') | |
__OBJ_SUB_SUB.addObject(__NOBJ) | |
__NOBJ = createObject('Bannana') | |
__NOBJ.registerSubObject('') | |
__OBJ_SUB_SUB.addObject(__NOBJ) | |
__OBJ_SUB.addObject(__OBJ_SUB_SUB) | |
__NOBJ = createObject('Tea') | |
__NOBJ.registerSubObject('') | |
__OBJ_SUB.addObject(__NOBJ) | |
return __OBJ_SUB | |
end)(_local) | |
_candy[0] = 123 | |
_candy[_G['$poof']] = 456 | |
_candy[(_G['$poof'] .. '_' .. 0)] = 567 | |
_i = 0 | |
while true do | |
if (not ((_i<5))) then break end | |
debugTimer((0)) | |
_count = 0 | |
_j = 0 | |
while true do | |
if (not ((_j<1000000))) then break end | |
_value = (10101010) + (999999) | |
_count = (_count + _value) | |
simpleCounter((0)) | |
_j = (_j + 1) | |
end | |
simpleCounter((1)) | |
debugTimer((1)) | |
_i = (_i + 1) | |
end | |
registerFunction('foo', nil, function(err) | |
return 123 | |
end) | |
echo((foo())) | |
_G['$ScriptErrorHash'] = 100 | |
quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment