All my moonslice attempts are on the back burner right now. You can use them for inspiration, but you'd be on your own. I had to look up lua syntax just to write the snippet I posted here. I've been doing a lot of hard-core JavaScript lately and it keeps pushing lua out of my brain.
On Tue, Jan 7, 2014 at 1:51 PM, develephant <[email protected]>wrote: > Hi Tim, > > That is very generous of you, thank you. My conversion was close to this, > but I was getting stuck on the "sub" part. Again, thank you. > > I'm using Luvit + Redis as the engine for a multi-user game/application > server mostly for Corona SDK developers. The memory footprint is amazingly > low. This will allow Lua code, which Corona is based on, to be written and > run on the server. I've put about a month into it and am very close to the > first alpha. The major difference in syntax of course is the node style of > doing things in Luvit, of which I have no problem educating developers on. > But... I have also noticed the moonslice-luv project. My question is > since the idea is to have the ability to code on the server in the same > language as the client ( Corona ) would it be wiser to use moonslice-luv? > I think I read in one of the archived lists that you we're trying to be > more Lua-centric with moonslice-luv. > > In either case, thank you so much for your help. I'll be paying it > forward. > > Cheers, > CB > develephant.net > > > On Tuesday, January 7, 2014 8:35:23 AM UTC-6, Tim Caswell wrote: > >> I was thinking more like this: >> >> local inputs = { >> "Hello world\nThis", >> " is a broken message", >> >> "\nI want to ", >> >> "reassemble it!\n\n", >> "end\n" >> } >> >> local function parseLine(emit) >> local buffer = "" >> return function (chunk) >> local start = 1 >> for i = 1, #chunk do >> local c = chunk:sub(i, i) >> p{buffer=buffer,i=i,c=c} >> if c == "\n" then >> emit(buffer .. chunk:sub(start, i - 1)) >> buffer = "" >> start = i + 1 >> end >> end >> >> buffer = buffer .. chunk:sub(start) >> end >> end >> >> >> local handle = parseLine(p) >> for i, chunk in ipairs(inputs) do >> handle(chunk) >> end >> >> >> https://gist.github.com/creationix/8300163 >> >> >> On Mon, Jan 6, 2014 at 9:42 PM, develephant <[email protected]>wrote: >> >>> Thank Tim, I really appreciate you taking the time to reply. I have to >>> tell you I have been eating and sleeping Luvit for the last month. As a >>> Lua junkie, I really have enjoyed learning about it and using it, so thank >>> you. >>> >>> Anyway, I found this bit of code for node. I just need to rework it for >>> Luvit. Does this look about right in theory? >>> >>> // define your terminator for easy reference, changesvar msgTerminator = >>> '\n'// create a place to accumulate your messages even if they come in >>> piecesvar buf; >>> >>> socket.on('data', function(data){ >>> // add new data to your buffer >>> buf += data; >>> >>> // see if there is one or more complete messages >>> if (buf.indexOf(msgTerminator) >= 0) { >>> // slice up the buffer into messages >>> var msgs = data.split(msgTerminator); >>> >>> for (var i = 0; i < msgs.length - 2; ++i) { >>> // walk through each message in order >>> var msg = msgs[i]; >>> >>> // pick off the current message >>> console.log('Data in server, sending to handle()'); >>> // send only the current message to your handler >>> worker.handle(msg, socket); >>> } >>> >>> buf = msgs[msgs.length - 1]; // put back any partial message into >>> your buffer >>> }}); >>> >>> Thanks again. >>> >>> >>> On Monday, January 6, 2014 3:21:41 PM UTC-6, Tim Caswell wrote: >>> >>>> There is no option built-in. I don't know of any existing libraries >>>> that do this. I would write it as a parser function that wraps the >>>> callback. >>>> >>>> local function parseLine(emit) >>>> -- setup local variables here >>>> return function (chunk) >>>> -- look for newlines in chunk flushing and emit()ing data as you >>>> come across them >>>> -- store leftover bytes in local variable for the next chunk. >>>> end >>>> end >>>> >>>> client:on("data", parseLine(function( line ) >>>> -- data is now line parsed. >>>> end)) >>>> >>>> >>>> >>>> >>>> On Mon, Jan 6, 2014 at 2:14 PM, develephant <[email protected]>wrote: >>>> >>>>> Hello, >>>>> >>>>> I'm looking to see if there is a simple way to read the luvit tcp >>>>> (smart) socket by line similar to the straight luasocket: >>>>> >>>>> client:*receive(*[pattern [, prefix]]*)* >>>>> >>>>> - '*l': reads a line of text from the socket. The line is >>>>> terminated by a LF character (ASCII 10), optionally preceded by a CR >>>>> character (ASCII 13). The CR and LF characters are not included in the >>>>> returned line. In fact, *all* CR characters are ignored by the >>>>> pattern. This is the default pattern; >>>>> >>>>> >>>>> http://w3.impa.br/~diego/software/luasocket/tcp.html#receive >>>>> >>>>> In luvit for example: >>>>> client:on( "data", function( data ) >>>>> --data is a line terminated by "\r\n" >>>>> end) >>>>> >>>>> I'm a newbie on node, but I can't seem to find any option. Is this >>>>> possible? Or will I need to parse it up myself? Any advice would be >>>>> appreciated. >>>>> >>>>> Cheers. >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "luvit" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "luvit" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "luvit" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "luvit" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
