From ddb0d3f63d4f9fa92554d3a4cb39b0664140c9b7 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 7 Jun 2013 10:18:15 +0000 Subject: [PATCH] LunaCON: properly generate references to gamevars named like Lua keywords. git-svn-id: https://svn.eduke32.com/eduke32@3855 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/lunacon.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 28621dabd..c13ee6a8d 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -431,10 +431,26 @@ end local BAD_ID_CHARS0 = "_/\\*?" -- allowed 1st identifier chars local BAD_ID_CHARS1 = "_/\\*-+?" -- allowed following identifier chars +local function truetab(tab) + local ttab = {} + for i=1,#tab do + ttab[tab[i]] = true + end + return ttab +end + +-- Lua 5.2 keywords. Not 5.1 because we use "goto" for codegen. +local LUA_KEYW = truetab { + "and", "break", "do", "else", "elseif", "end", + "false", "for", "function", "goto", "if", "in", + "local", "nil", "not", "or", "repeat", "return", + "then", "true", "until", "while" +} + -- Return the Lua code by which the CON object is referenced in the -- translated code. local function mangle_name(name, prefix) - if (name:match("^[A-Za-z_][A-Za-z_0-9]*$")) then + if (name:match("^[A-Za-z_][A-Za-z_0-9]*$") and not LUA_KEYW[name]) then return format("_%s.%s", prefix, name) else return format("_%s[%q]", prefix, name)