aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-04 22:47:37 +1000
committerDavid Walter Seikel2012-02-04 22:47:37 +1000
commit6b097d337444a0e02efc6cebed08a860d2e435ed (patch)
treeb923c45c8f71068d3acc705d813a794a44cff030 /LuaSL
parentSet variables to a proper value if otherwised unitialized. (diff)
downloadSledjHamr-6b097d337444a0e02efc6cebed08a860d2e435ed.zip
SledjHamr-6b097d337444a0e02efc6cebed08a860d2e435ed.tar.gz
SledjHamr-6b097d337444a0e02efc6cebed08a860d2e435ed.tar.bz2
SledjHamr-6b097d337444a0e02efc6cebed08a860d2e435ed.tar.xz
Implement typecasts when needed. Actually, doing some extras for the moment.
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LSL.lua32
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h3
-rw-r--r--LuaSL/src/LuaSL_compile.c13
3 files changed, 45 insertions, 3 deletions
diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua
index cc9b454..1e7cc13 100644
--- a/LuaSL/src/LSL.lua
+++ b/LuaSL/src/LSL.lua
@@ -311,6 +311,38 @@ function LSL.stateChange(x)
311 end 311 end
312end; 312end;
313 313
314function LSL.floatTypecast(x)
315 local temp = tonumber(x)
316 if nil == temp then temp = 0 end
317 return temp;
318end
319
320function LSL.integerTypecast(x)
321 local temp = tonumber(x)
322 if nil == temp then temp = 0 end
323 return temp;
324end
325
326function LSL.keyTypecast(x)
327 return "" .. x;
328end
329
330function LSL.listTypecast(x)
331 return {x};
332end
333
334function LSL.rotationTypecast(x)
335 return x;
336end
337
338function LSL.stringTypecast(x)
339 return "" .. x;
340end
341
342function LSL.vectorTypecast(x)
343 return x;
344end
345
314 346
315return LSL; 347return LSL;
316 348
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 6709236..3c30129 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -157,7 +157,8 @@ typedef enum
157 MF_PREINC = 32, 157 MF_PREINC = 32,
158 MF_POSTDEC = 64, 158 MF_POSTDEC = 64,
159 MF_POSTINC = 128, 159 MF_POSTINC = 128,
160 MF_LSLCONST = 256 160 MF_LSLCONST = 256,
161 MF_TYPECAST = 512
161} miscFlags; 162} miscFlags;
162 163
163struct _allowedTypes 164struct _allowedTypes
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index f3fddef..cd8494a 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -1217,7 +1217,11 @@ LSL_Leaf *addTypecast(LSL_Leaf *lval, LSL_Leaf *type, LSL_Leaf *rval, LSL_Leaf *
1217 if (lval) 1217 if (lval)
1218 { 1218 {
1219 if (type) 1219 if (type)
1220 {
1220 lval->basicType = type->basicType; 1221 lval->basicType = type->basicType;
1222 if ((expr) && (OT_integer == type->basicType)) // TODO - Should be from string, but I guess I'm not propagating basic types up from function calls and parenthesis?
1223 lval->value.parenthesis->flags |= MF_TYPECAST;
1224 }
1221 // Actualy, at this point, type is no longer needed. 1225 // Actualy, at this point, type is no longer needed.
1222 lval->toKen = tokens[LSL_TYPECAST_OPEN - lowestToken]; 1226 lval->toKen = tokens[LSL_TYPECAST_OPEN - lowestToken];
1223 } 1227 }
@@ -1401,7 +1405,7 @@ Explicit type casting -
1401 Leading spaces are ignored, as are any characters after the run of digits. 1405 Leading spaces are ignored, as are any characters after the run of digits.
1402 All other strings convert to 0. 1406 All other strings convert to 0.
1403 Which means "" and " " convert to 0. 1407 Which means "" and " " convert to 0.
1404 Strings in hexadecimal format will work. 1408 Strings in hexadecimal format will work, same in Lua (though Lua can't handle "0x", but "0x0" is fine).
1405 keys <-> string 1409 keys <-> string
1406 No other typecasting can be done with keys. 1410 No other typecasting can be done with keys.
1407 float -> string 1411 float -> string
@@ -1770,8 +1774,13 @@ static void outputRawParenthesisToken(FILE *file, outputMode mode, LSL_Parenthes
1770{ 1774{
1771 if ((OM_LUA == mode) && (LSL_TYPECAST_OPEN == parenthesis->type)) 1775 if ((OM_LUA == mode) && (LSL_TYPECAST_OPEN == parenthesis->type))
1772 { 1776 {
1773 fprintf(file, " --[[(%s)]] ", typeName); 1777 if (MF_TYPECAST & parenthesis->flags)
1778 fprintf(file, " _LSL.%sTypecast(", typeName);
1779 else
1780 fprintf(file, " --[[%s]] ", typeName);
1774 outputLeaf(file, mode, parenthesis->contents); 1781 outputLeaf(file, mode, parenthesis->contents);
1782 if (MF_TYPECAST & parenthesis->flags)
1783 fprintf(file, ") ");
1775 return; 1784 return;
1776 } 1785 }
1777 1786