This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package.cpath = "luaclib/?.so" | |
local socket = require "clientsocket" | |
local crypt = require "crypt" | |
local input = {} | |
local function readpackage() | |
local line = table.remove(input, 1) | |
if line then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- cjson is clone from https://github.com/mpx/lua-cjson/ | |
-- time lua testcjson.lua 1 1000000 (decode : 15.57s) | |
-- time lua testcjson.lua 1000000 1 (encode : 19.53s) | |
local cjson = require "cjson" | |
local ab = { | |
person = { | |
{ | |
name = "Alice", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
struct sslice { | |
const char *ptr; | |
size_t sz; | |
}; | |
int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
In windows 7 64, Intel i5-2500 CPU @ 3.30 GHz | |
$ lua testescape.lua old | |
Total string 44128 | |
use time: 0.197 | |
use mem: 18130.474609375 | |
$ lua testescape.lua new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
#define QSZ (1 << 10) | |
#define QMSK (QSZ - 1) | |
struct queue { | |
volatile uint32_t head; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local index_cache = setmetatable({} , { __mode = "k" }) | |
local meta = {} | |
function meta.__newindex(t, k, v) | |
index_cache[t] = nil | |
rawset(t, k, v) | |
end | |
function meta.__pairs(t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local FUNC_TEMP=[[ | |
local $ARGS | |
return function(...) | |
$SOURCE | |
end, | |
function() | |
return {$LOCALS} | |
end | |
]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local skynet = require "skynet" | |
require "skynet.manager" | |
local mode = ... | |
if mode == "slave" then | |
skynet.start(function() | |
skynet.dispatch("lua", function(session, address, ti, ...) | |
if session == 0 then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local M = {} | |
function M.test(...) | |
print(...) | |
end | |
return M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local DIRSEP, PATSEP, MARK = package.config:match "(.-)\n(.-)\n(.-)\n" | |
MARK = MARK:gsub(".", function (c) return "%" .. c end) | |
-- todo: replace your own readable function | |
local function readable(filename) | |
local f = io.open(filename) | |
if f then | |
f:close() | |
return true | |
end |