[ create a new paste ] login | about

nepta

Name:
Email:
Site/Blog:
Location:
Default language: Lua
Favorite languages: Lua
About:

Saved pastes by nepta:

Lua, pasted on Nov 6:
1
2
3
s = "123"
b = tonumber(s) ~= nil
print(b)
view (3 lines, 1 line of output)
Lua, pasted on Nov 5:
1
print(arg[0])
view (1 line, 1 line of output)
Lua, pasted on Nov 5:
1
2
3
d = os.time {day= 19, month= 9, year= 1999}
x = os.date("%F",d)
print(x)
view (3 lines, 1 line of output)
Lua, pasted on Nov 5:
1
2
3
r = "htt+p"

print( string.match("htttttttttttttttttp://www.programming-idioms.org", r))
view (3 lines, 1 line of output)
Lua, pasted on Nov 5:
1
2
3
4
s = "programming-idioms.org"
prefix = "pro"

b = s:find(prefix) == 1
...
view (6 lines, 1 line of output)
Lua, pasted on Nov 5:
1
2
3
4
x = "programming-idioms"
y = "idioms"

i = x:find(y)
...
view (6 lines, 1 line of output)
Lua, pasted on Nov 5:
1
2
3
4
s1 = "be concise, be useful"
w = "be"
s2 = s1:gsub(w,"")
print(s2)
view (4 lines, 1 line of output)
Lua, pasted on Nov 5:
1
2
3
4
5
s = "Please don't reinvent the wheel."
chunks = {}

for substring in s:gmatch("%S+") do
   table.insert(chunks, substring)
...
view (8 lines, 1 line of output)
Lua, pasted on Nov 5:
1
2
math.randomseed( os.time() )
print( math.random() )
view (2 lines, 1 line of output)
Lua, pasted on Nov 5:
1
2
3
x = 0.15625
s = string.format("%.1f%%\n",x*100)
print(s)
view (3 lines, 2 lines of output)
Lua, pasted on Apr 8:
1
2
3
4
5
--[[
inline string use either " or ',
for multiline string, lua use long bracket notation, in the form:
[=[ multi
line
...
view (17 lines, 3 lines of output)
Lua, pasted on Apr 8:
1
2
3
x = 123.456789
s = string.format("%.2f",x)
print(s)
view (3 lines, 1 line of output)
Lua, pasted on Apr 8:
1
2
3
4
5
x = "hello world, hello moon"
y = "hello"
z = "adios"
x2 = x:gsub(y,z)
print(x2)
view (5 lines, 1 line of output)
Lua, pasted on Apr 8:
1
2
3
4
5
items = {
   "a","z","e","r","t","y",
   "u","i","o","p","q","s",
   "d","f","g","h","j","k",
   "l","m","w","x","c","v",
...
view (15 lines, 2 lines of output)
Lua, pasted on Apr 7:
1
2
3
4
s = {'a','b','d','e','f'}
print(table.concat(s,","))
table.insert(s,3,'c')
print(table.concat(s,","))
view (4 lines, 2 lines of output)
Lua, pasted on Apr 7:
1
2
print(os.date())
print(os.time())
view (2 lines, 2 lines of output)
Lua, pasted on Apr 7:
1
2
3
s = "miaou123"
t = s:sub(-5)
print(s,t)    
view (3 lines, 1 line of output)
Lua, pasted on Apr 7:
1
2
3
4
5
local a = 0
function someThing()
	print "do some thing"
	a = a+1
end
...
view (17 lines, 9 lines of output)
Lua, pasted on Apr 7:
1
2
3
function isBlank(s)
	return s ~= nil and s:match("%S") ~= nil
end
...
view (9 lines, 4 lines of output)
Lua, pasted on Apr 7:
1
2
3
4
5
function f(x)
	return x + 1
end

function g(x)
...
view (17 lines, 2 lines of output)
Lua, pasted on Apr 7:
1
2
3
4
5
function curry2(f)
   return function(a)
      return function(b)
         return f(a,b)
      end
...
view (18 lines, 3 lines of output)
Lua, pasted on Apr 7:
1
2
3
4
5
function search(m, x)
   for i,v1 in ipairs(m) do
      for j,v2 in ipairs(v1) do
         if v2 == x then return i,j end
      end
...
view (18 lines, 1 line of output)
Lua, pasted on Apr 7:
1
2
3
4
5
function sum(x)
   local s = 0
   for i,v in ipairs(x) do
      s = s + v
   end
...
view (9 lines, 1 line of output)
Lua, pasted on Apr 7:
1
2
3
4
5
function f(n)
   local function f_(factorial,n)
      if n < 2 then return factorial end
      return f_(factorial*n, n-1)
   end
...
view (9 lines, 1 line of output)
Lua, pasted on Apr 7:
1
2
3
4
5
local array = setmetatable({},{
	__index = function(t,k)
		t[k] = setmetatable({},{
			__index = function(t,k)
				t[k] = 0
...
view (16 lines, 3 lines of output)