Codea 2.3 Beta

Good stuff @toffer - never realised that! Well you learn something every day!

@toffer @andymac3d The only problem is each print goes to seperate area, so you can only copy one print line at a time. There have been times where I wanted to copy a lot of print lines at once but couldn’t.

@dave1707 - Something I’ve done to simulate buttons (question with multiple choices) from the output panel was to check the clipboard content in the draw loop, each time it was changed from it’s previous value, mean the user has touched the output panel, so I could trigger something depending on it. Maybe it can be applicable to build a clipboard buffer, each time the clipboard has changed, take it’s value, push it to the buffer and replace the clipboard with the content of the buffer?

@toffer One thing I would do if I wanted to select what was printed was to concat innate everything to a string and then print the string at the end. All of the information being printed would print in one print area and able to be copied. Of course I don’t do that very often.

@toffer that’s a pretty brilliant way of detecting touches in the output area.

In the new update, the camera still flips upside down when you hit restart during live feed

@Simeon, when saveText creates a file for you, it adds a period to the end of the file name, and it now fails to edit any text file if the file doesn’t have an extra period at the end (ex saveText("Project:Example", "test") won’t save anything to Project:Example, but will to Project:Example.

Also, I had a Parameters program in my regular projects section, as well as one in my examples section, which get confused between each other when closing, opening, or editing. (one is not a copy of the other, just a program with the same name) Since they are in different collections I would expect they wouldn’t mess with each other.

@JakAttak thank you for finding that, I think I know what the cause is. Will fix for next update.

Will look into the confused collections issue. I believe one of them actually has a different name — it’s just that the “localized” name is showing instead on your copied version.

@Simeon, sounds good.

Not sure if anyone has mentioned this yet but tweens can no longer take zero as the time, any reason for this?

@Simeon The LuaSocket API in Codea seems to be different from the standard, none of the examples from the tutorials I’ve looked up have worked in Codea. They all call local socket = require("socket"), which doesn’t return anything in Codea, if I try to call socket.tcp() and use that as the socket object, it gives errors on socket.bind(...), saying it expected some weird “socket{master}” variable as the first parameter or something. Just calling socket.bind gives a nil error, etc.

Is there any documentation on Codea’s version of LuaSocket?

@JakAttak they never could (it used to bump the value to 0.001 or so) but I figured actually asserting this is better behaviour for the API. If you want to do a 0 tween, then you’ll just have to use a very small value.

@SkyTheCoder Codea uses LuaSocket 3.0, documentation is on the github repo here https://github.com/diegonehab/luasocket/tree/master/doc

@Simeon Do you think you could re-add bumping the 0 to a 0.001 in the tween library? It kind of broke most of my libraries, where I used tween.delay(0, ...) to run code after 1 frame had passed (usually to hook into the draw function). Maybe just put a warning when you use it, like what happens when you call watch(), parameter(), etc.

Edit: here’s a fix that automatically changes it to 0.001, but not everyone might have it, so I still would want it to be built-in:

_vars = {}

local mt = debug.getmetatable(tween)

local _t = mt.__call

mt.__call = function(del, ...)
    local delay = del
    if delay == 0 then
        delay = 0.001
    end
    local t = _t(delay, ...)
    table.insert(_vars, t)
    return t
end

local _td = tween.delay

tween.delay = function(del, ...)
    local delay = del
    if delay == 0 then
        delay = 0.001
    end
    local t = _td(delay, ...)
    table.insert(_vars, t)
    return t
end

debug.setmetatable(tween, mt)

@SkyTheCoder I could add the 0 case support just to tween.delay and maybe a version which just accepts a callback (tween.delay( func ))

@SkyTheCoder wow, you’ve got pretty fluent with metatables! Why do you use different methods for the 2 functions? Why not overwriting tween() function directly, as you do for tween.delay, instead of redefining mt._call? Just to know.

@Jmv38 Tween is actually a table/metatable, not a function, the only reason you can call it like a function is because metatables can have a _call function.

@SkyTheCoder does this work for you?

    local t = socket.tcp() 
    assert(t:bind("*", 5088)) 
    t:close()

Edit: I Think I see the problem, never mind. Will fix for next build.

@SkyTheCoder - socket.bind is a shortcut method not implemented in this version (also I didn’t find it).
It seem that the the host binding fail often, that’s not a big deal. Not tested but I think with a check, closing and re-bind it could work.

A dummy repl to test from a telnet connection (change the host with your local ip)

function setup()
    server = socket.tcp()
    -- Replace with your local IPad ip
    server:bind("192.168.1.23",52096)
    server:listen()
    server:settimeout(0.0)
    local ip,port = server:getsockname()
    print("please telnet to", ip, "on port", port)
    client = nil
    buf = {}
end

local _twu = tween.update
tween.update = function(...)
    if not client then
        client = server:accept()
        if client then
            client:settimeout(0.0)
            local ip,po = client:getsockname()
            client:send("Welcome to the REPL mr(s) "..ip.." "..po.."\
")
            client:send("Type bye to quit\
")
        end
    end
    if client then
        local lin, err = client:receive()
        if not err then
            if lin == "bye" then
                client:close()
                client = nil
            else
                table.insert(buf,lin)
                local f,e = load(table.concat(buf,"\
"))
                if not e then
                    f()
                    client:send("> eval\
")
                    buf = {}
                end
          end
        end
    end
    _twu(...)
end

As part of the Codea comms/sockets discussion - can anyone recommend a good Lua JSON parser/encoder for Lua 5.3? Seems most of the ones I’ve found/used only work with previous versions.

It would be great if there was some native support within Codea for this, as serialising/un-serialising data (from the web or otherwise) is really useful.

@andymac3d there is some filters in the mime table (no json one) : http://w3.impa.br/~diego/software/luasocket/mime.html. +1 for native json support.