Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
plut committed Apr 11, 2024
1 parent 8135b74 commit e363414
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ w: watch
watch:
cargo watch -s 'clear;cargo c --color=always 2>&1 | head -30'

t: test
test:
# low-level (SQL) test
sqltest:
rm -rf $(BG)/simod_out
# $(RUN) -O init.log init -B
echo "update \"items\" set price=5,name='A new name for Albruin' where id='sw1h34';" | sqlite3 $(DB)
Expand All @@ -44,7 +44,9 @@ test:
# $(RUN) -O add.log add target
$(RUN) -O save.log save

x:
# high-level (Lua) test
t: test
test:
cargo build
@-echo "delete from add_items" | sqlite3 game.sqlite
@-echo "delete from add_items_abilities" | sqlite3 game.sqlite
Expand All @@ -53,7 +55,7 @@ x:
@-echo "delete from edit_items_abilities" | sqlite3 game.sqlite
@-echo "delete from edit_items_effects" | sqlite3 game.sqlite
# $(RUN) -O init.log init -B
$(RUN) -O add.log add t
$(RUN) -O add.log add phony_target
@-echo "select * from add_items" | sqlite3 game.sqlite
@-echo "select parent,id from items_abilities where parent in (select id from add_items)" |sqlite3 game.sqlite
@-echo "select parent,root,id,opcode from items_effects where root in (select id from add_items)" |sqlite3 game.sqlite
Expand Down
39 changes: 25 additions & 14 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ local function strdump(o, limit, level)
if k == i then
i = i+1
elseif type(k) == 'string' then
s = s..'[38;5;65m'..k..'[m='
s = s..'[38;5;64m'..k..'[m='
else
s = s..'[[38;5;65m'..k..'[m]='
s = s..'[[38;5;64m'..k..'[m]='
end
if v == o then
s = s .. "!self!,"
Expand Down Expand Up @@ -102,7 +102,7 @@ function log:print(...)
error("deep recursion")
end
for i = 1, self.level do
io.write("")
io.write("\x1b[38;5;137m│\x1b[m")
end
io.write(...)
io.write("\n")
Expand All @@ -127,9 +127,9 @@ function log:report(event)
end
end
local caller = debug.getinfo(4)
self:print("┌─▶"..frame.namewhat.." "..bold(yellow(frame.name).." "
..cyan(frame.linedefined))
.." " ..blue("from "..caller.currentline))
self:print("\x1b[38;5;137m┌─▶"..frame.namewhat.."\x1b[m "..bold(yellow(frame.name).." "
..cyan("line "..frame.linedefined))
.." " ..green("called from "..caller.currentline))
self.level = self.level + 1
-- self:print(stack)
-- self:print(strdump(frame))
Expand All @@ -145,7 +145,7 @@ function log:report(event)
-- end
if self:isenabled(frame) then
self.level = self.level - 1
self:print("└─ "..frame.namewhat.." "..frame.name)
self:print("\x1b[38;5;137m└─ "..frame.namewhat.."\x1b[m "..frame.name)
end
end
end
Expand Down Expand Up @@ -295,7 +295,7 @@ function resource_mt:read(key)
return setmetatable({_fields = vals, _id=key}, self)
end
function resource_mt:index(key)
log("indexing ", strdump(self, 1), " with key ", key)
log("indexing ", strdump(self, 1), " with key ", blue('"', key, '"'))
local methods = getmetatable(self)
-- if this key represents an existing method in the metatable,
-- return the method:
Expand Down Expand Up @@ -433,7 +433,9 @@ function resvec_mt:index(i)
-- if this key represents an existing method in the metatable,
-- return the method:
do local meth = methods[i]; if meth ~= nil then return meth end end
log("no method found, accessing _keys")
local key = self._keys[i]
log("found key = "..tostring(key))
if key == nil then return nil end
return methods.each:read(key)
end
Expand Down Expand Up @@ -556,18 +558,27 @@ function test_core()
-- dump(simod.schema)
end
local items_mt = simod.schema.items.methods
print("\x1b[31m████ test = items_mt:read\x1b[m")
local TOP_COLORS = {1,16,17,18,52,53,54,58,88,89,124,125,126,160,196,197,233,234,236}
math.randomseed(os.time())
local TOP_PREFIX = "\x1b[7;38;5;"..TOP_COLORS[math.random(#TOP_COLORS)].."m "
local function top(x)
print(TOP_PREFIX..x.."\x1b[m")
end
log:ignore(top)
top('test = items_mt:read("ring02")')
test = items_mt:read("ring02")
print("\x1b[31m████ test.weight = 10\x1b[m")
top("test.weight = 10")
test.weight = 10; dump(test)
print("\x1b[31m████ test_eff = test.effects\x1b[m")
top("test_eff = test.effects")
test_eff = test.effects
print("\x1b[31m████ dump(test_eff[2])\x1b[m")
top("dump(test_eff)")
dump(test_eff)
top("dump(test_eff[2])")
dump(test_eff[2])

print("\x1b[31m████ test_eff:insert(2,{})\x1b[m")
top("test_eff:insert(2,{})")
test_eff:insert(2, {})
print("\x1b[31m████ dump(test_eff[2])\x1b[m")
top("dump(test_eff[2])")
dump(test_eff[2])

-- mt = getmetatable(test_eff)
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ pub trait Pack: Sized {
/// Helper function used to check forced headers.
fn read_bytes(f: &mut impl Read, n: usize)->io::Result<Vec<u8>> {
let mut buf = vec![0u8; n];
// let mut buf = Vec::<u8>::with_capacity(n);
// unsafe { buf.set_len(n); }
f.read_exact(&mut buf)?; Ok(buf)
}
/// function which checks that a header is correct.
Expand Down Expand Up @@ -3180,6 +3178,8 @@ impl RecurseState<PushRow<'_>> for PushState<'_,'_> {
/// - list("item_abilities", "sw1h34") etc.
/// All code with a higher level is written in lua and loaded from the
/// "init.lua" file.
/// XXX: for now we only load the "init.lua" file, independently of the
/// target argument passed
pub fn command_add(db: impl DbInterface, target: &str)->Result<()> {
// Allows `debug` to be used in Lua code:
let lua = unsafe { Lua::unsafe_new() };
Expand Down

0 comments on commit e363414

Please sign in to comment.