From a60bb6fbc1ad1e4e7c100d1ccd166d6e219473ac Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 14 May 2014 19:50:41 +1000 Subject: LSL's EOF sucks, Lua's 0 isn't false sucks more. Work around both. --- lib/LSL.lua | 18 ++++++++++++++++-- src/LuaSL/LuaSL_compile.c | 3 ++- src/love/love.c | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/LSL.lua b/lib/LSL.lua index cdb560b..571ecf1 100644 --- a/lib/LSL.lua +++ b/lib/LSL.lua @@ -169,6 +169,7 @@ local function value2string(value, Type) local temp = "" if "float" == Type then temp = temp .. value +-- elseif "boolean" == Type then if value then temp = '"true"' else temp = '"false"' end elseif "integer" == Type then temp = temp .. value elseif "key" == Type then temp = "\"" .. value .. "\"" elseif "list" == Type then temp = "[" .. args2string(true, unpack(value)) .. "]" @@ -388,7 +389,8 @@ local constants = newConst("integer", "TYPE_INVALID", 0), newConst("string", "NULL_KEY", "00000000-0000-0000-0000-000000000000"), - newConst("string", "EOF", "\\n\\n\\n"), -- Corner case, dealt with later. +-- newConst("string", "EOF", "\\n\\n\\n"), -- Corner case, dealt with later. + newConst("string", "EOF", "EndOfFuckingAround"), -- Corner case, dealt with later. newConst("rotation", "ZERO_ROTATION", {x=0.0, y=0.0, z=0.0, s=1.0}), newConst("vector", "ZERO_VECTOR", {x=0.0, y=0.0, z=0.0}), @@ -770,7 +772,8 @@ function LSL.mainLoop(sid, name, x) SID = sid scriptName = name - LSL.EOF = "\n\n\n" -- Fix this up now. +-- LSL.EOF = "\n\n\n" -- Fix this up now. + LSL.EOF = "EndOfFuckingAround" -- Fix this up now. LSL.stateChange(x); waitAndProcess(false) @@ -912,4 +915,15 @@ function LSL.listConcat(a, b) return result; end +-- Lua really hates 0, it's not false, and it can't be a table index. +function LSL.toBool(x) + local v = x + local t = type(v) + if 'boolean' == t then return v end + if 'number' == t then return (v ~= 0) end + if 'nil' == t then return false end + -- Is an empty string, empty list, zero vector/rotation false? Fucked if I know. + return true +end + return LSL; diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c index 90c9ac1..e31e157 100644 --- a/src/LuaSL/LuaSL_compile.c +++ b/src/LuaSL/LuaSL_compile.c @@ -1613,11 +1613,12 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state fprintf(file, " "); if (LSL_ELSE != statement->type) { + fprintf(file, "_LSL.toBool("); if (statement->parenthesis) outputRawParenthesisToken(file, mode, statement->parenthesis, ""); else outputLeaf(file, mode, statement->expressions); - fprintf(file, " then\n"); + fprintf(file, ") then\n"); } if (statement->block) outputRawBlock(file, mode, statement->block, FALSE); diff --git a/src/love/love.c b/src/love/love.c index db4c557..858ba40 100644 --- a/src/love/love.c +++ b/src/love/love.c @@ -436,7 +436,7 @@ static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *e sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", \"%s\")", key, temp); } else - sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", [[\\n\\n\\n]])", key); + sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", \"EndOfFuckingAround\")", key); } close(fd); -- cgit v1.1