minetest-mods / mesecons

Mod for Minetest that adds digital circuitry [=Minecraft redstone]
https://mesecons.net
Other
211 stars 120 forks source link

commented prohibited commands (luacontroller) #91

Closed khonkhortisan closed 9 years ago

khonkhortisan commented 11 years ago
fork = spoon
--for prohibited_command = 1, infinity do print("Prohibited command: while") end

Both of these give Prohibited command: for Apparently you can't redefine keywords. It'll have to be a smart search.

Jeija commented 11 years ago
    -- remove -- comments
    for _, l in ipairs(string.split(nc, "\n")) do
        for i = 1, #l do
            local c = l:sub(i, i+1)
            if c == "--" then
                cleancode = cleancode..l:sub(1, i-1)
                break
            elseif i == #l then
                cleancode = cleancode..l
            end
        end
    end

That would be some code for -- comments. That is quite hacky, so anyone familiar with regexes for single-line and multi-line comments that work with lua's implementation in gsub?

Uberi commented 11 years ago
cleancode = nc:gsub("--[^\r\n]*", "")

This might work, but like your example, it doesn't take into account whether the -- is inside a string, like in this snippet:

x = "--this is not really a comment"
Jeija commented 9 years ago

As there are no prohibited commands anymore due to the instruction counter patch by @ShadowNinja, (#172) there is no need for this anymore. Closing this pull therefore.