- ComputerCraft | Programmable Computers for Minecraft
- → Eric's Content
Eric's Content
There have been 88 items by Eric (Search limited from 10-February 22)
#114972 A nice, small class implementation.
Posted by
Eric
on 04 May 2013 - 03:44 AM
in
APIs and Utilities
Here's my more complex version, inspired by how python handles classes and descriptors: https://github.com/eric-wieser/pylua
There are some examples there at the bottom of the page.
#100250 BasicUtils v1.5
Posted by
Eric
on 22 March 2013 - 12:35 PM
in
APIs and Utilities
local t = {}
t.value = 1
t.self = t
local q = deepcopy(t)
assert(q.self == q)
#91959 Block API v0.7
Posted by
Eric
on 28 February 2013 - 08:47 AM
in
APIs and Utilities
#91085 adding object API functions to object metatables
Posted by
Eric
on 25 February 2013 - 10:49 AM
in
Suggestions
#91032 adding object API functions to object metatables
Posted by
Eric
on 25 February 2013 - 07:26 AM
in
Suggestions
#90988 [1.48] os.queueEvent/os.pullEvent fail for 8-bit strings
Posted by
Eric
on 25 February 2013 - 03:31 AM
in
Bugs
fs.makeDir('d') -- empty directory
local h = fs.open('d/'..string.char(128), 'w') -- odd filename
assert(h == nil) -- which doesn't get created - fair enough
-- So there should be no files in the directory, right?
local files = fs.list('d')
assert(#files == 1) -- except there are
-- Can you guess what the name of the file is?
local file = files[1]
print(files[1]:byte(1, math.huge))
That outputs:239 190 128
#90983 reading pointers
Posted by
Eric
on 25 February 2013 - 03:15 AM
in
Ask a Pro
TheOriginalBIT, on 25 February 2013 - 01:59 AM, said:
More accurately, Events don't work with string.dump
#90980 [1.48] os.queueEvent/os.pullEvent fail for 8-bit strings
Posted by
Eric
on 25 February 2013 - 02:52 AM
in
Bugs
Test #1: check that :byte and .char work as expected:
for i = 0, 255 do
local c = string.char(i)
local j = c:byte()
if j ~= i then
print(("FAIL: Converting %d from int->char->int gave %d"):format(i, j))
end
end
PassesTest #2: Check that strings are preserved through events:
for i = 0, 255 do
local c = string.char(i)
os.queueEvent('test', c)
local _, c2 = os.pullEvent('test')
assert(#c == 1 and #c2 == 1) -- to prove these are single-byte strings
local j = c2:byte()
if c ~= c2 then
print(("FAIL: Passing %d through an event gives %d"):format(i, j))
end
end
Fails:FAIL: Passing 128 through an event gives 239 FAIL: Passing 129 through an event gives 239 FAIL: Passing 130 through an event gives 239 ... FAIL: Passing 255 through an event gives 239
To summarize, either queueEvent or pullEvent fail to pass strings containing characters above character 127.
This bug is almost certainly present in 1.5 as well, although I haven't tested it.
#90463 [New Lua Function] os.getVersion (yes I know there is os.version)
Posted by
Eric
on 23 February 2013 - 10:21 AM
in
Suggestions
1.0 1.1 1.2 ... 1.8 1.9 1.10 1.11Those are in order of increasing version, but not numeric or lexographic order.
Keep it as a string, or switch to an array of integers.
#85929 The HTTP API should allow us to set headers.
Posted by
Eric
on 10 February 2013 - 11:23 AM
in
Suggestions
@raineth: Nice! (+1)
#83219 [API][MiscPeripherals] Music API (Iron Note Block)
Posted by
Eric
on 03 February 2013 - 06:01 AM
in
APIs and Utilities
a=peripheral.wrap("top")
b=peripheral.wrap("bottom")
c=peripheral.wrap("front")
d=peripheral.wrap("back")
e=peripheral.wrap("left")
f=peripheral.wrap("right")
if a then
g=a
elseif b then
g=b
elseif c then
g=c
elseif d then
g=d
elseif e then
g=e
elseif f then
g=f
else
-- ...
consider using:
g = peripheral.wrap("top")
or peripheral.wrap("bottom")
or peripheral.wrap("front")
or peripheral.wrap("back")
or peripheral.wrap("left")
or peripheral.wrap("right")
if not g then
-- ...
Here's the same api, in half as many lines.
#80815 Creating a New Computercraft Function.
Posted by
Eric
on 27 January 2013 - 06:27 AM
in
Ask a Pro
remiX, on 26 January 2013 - 10:52 AM, said:
elseif type(lengthOn) ~= "string" then error("Bad argument #3, number expected - got " .. type(lengthOn))
elseif type(lengthOff) ~= "string" then error("Bad argument #4, number expected - got " .. type(lengthOff))
elseif type(nTimes) ~= "string" then error("Bad argument #5, number expected - got " .. type(nTimes))
I would say avoid type checking where possible - it violates the principle of duck typing.
#80623 run functions of other files
Posted by
Eric
on 26 January 2013 - 12:44 PM
in
Ask a Pro
Put "3/4" in a file and run it (the CC Lua shell doesn't show this behavior) and you'll see what I mean.
#79352 Octree - Efficient way of storing, and querying 3D data
Posted by
Eric
on 23 January 2013 - 10:34 AM
in
APIs and Utilities
BigSHinyToys, on 23 January 2013 - 09:08 AM, said:
NeverCast, on 23 January 2013 - 08:46 AM, said:
It would automatically return nil if it didn't exist.
That said, the code is impressive.. and maybe one day it'll have a cause!
local tTable = {}
local function get(x,y,z)
return tTable[table.concat({x,y,z},"-")]
end
local function set(x,y,z,val)
tTable[table.concat({x,y,z},"-")] = val
end
Or in a cooler way:
local grid_mt = {
__index = function(self, t)
return rawget(self, table.concat(t, "-"))
end,
__index = function(self, t, v)
return rawset(self, table.concat(t, "-"), v)
end
}
local grid1 = setmetatable({}, grid_mt)
local grid2 = setmetatable({}, grid_mt)
grid1[{1, 2, 3}] = 3
grid2[{4, 5, 6}] = grid1[{1, 2, 3}]
- ComputerCraft | Programmable Computers for Minecraft
- → Eric's Content


