starlit  Diff

Differences From Artifact [7fd77150af]:

To Artifact [42f785b164]:


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
-- from the game API

local fn = {}
local lib = ...

-- WARNING: INEFFICIENT AS FUCK
fn.identify = function(objref) --> objectid
	for _, o in pairs(minetest.get_connected_players()) do
		if objref == o then return o:get_player_name(), 'player' end
	end
	for id, le in pairs(minetest.luaentities) do
		if le.object == objref then return id, 'entity' end
	end
end

fn.handle = lib.class {
	__newindex = function(self,key,newval)
		local hnd if self.player
			then hnd = minetest.get_player_by_name(self._id)
			else hnd = minetest.luaentities[self._id]
		end
		if key == 'id' then
			if type(newval) == 'string' then
				local p = minetest.get_player_by_name(newval)
				if p then
					self._id = newval
					self.player = true
					return
				end
			end
			if minetest.luaentities[newval] then
				self._id = newval
				self.player = false
			else error('attempted to assign invalid ID to entity handle') end
		elseif key == 'obj' then
			local no, kind = fn.identify(newval)
			if no then
				self._id = no
................................................................................
			else error('attempted to assign invalid ObjectRef to entity handle') end
		elseif key == 'stack' and self.kind == 'item' then
			hnd:set_item(newval)
		end
	end;
	__index = function(self,key)
		local hnd if self.player then
			hnd = minetest.get_player_by_name(self._id)
		else
			hnd = minetest.luaentities[self._id]
		end
		if key == 'online' then
			return hnd ~= nil
		elseif key == 'id' then
			if self.player then return nil
			else return self._id end
		elseif key == 'obj' then
................................................................................
					return maxy-miny, miny
				else return 0 end
			end
		end
	end;
	construct = function(h)
		local kind, id
		if type(h) == 'string' and minetest.get_player_by_name(h) ~= nil then
			kind = 'player';
			id = h
		elseif minetest.luaentities[h] then
			kind = 'entity';
			id = h
		else id, kind = fn.identify(h) end

		if not id then
			error('attempted to construct object handle from invalid value')
		end







|


|







|
|



|






|







 







|

|







 







|


|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
-- from the game API

local fn = {}
local lib = ...

-- WARNING: INEFFICIENT AS FUCK
fn.identify = function(objref) --> objectid
	for _, o in pairs(core.get_connected_players()) do
		if objref == o then return o:get_player_name(), 'player' end
	end
	for id, le in pairs(core.luaentities) do
		if le.object == objref then return id, 'entity' end
	end
end

fn.handle = lib.class {
	__newindex = function(self,key,newval)
		local hnd if self.player
			then hnd = core.get_player_by_name(self._id)
			else hnd = core.luaentities[self._id]
		end
		if key == 'id' then
			if type(newval) == 'string' then
				local p = core.get_player_by_name(newval)
				if p then
					self._id = newval
					self.player = true
					return
				end
			end
			if core.luaentities[newval] then
				self._id = newval
				self.player = false
			else error('attempted to assign invalid ID to entity handle') end
		elseif key == 'obj' then
			local no, kind = fn.identify(newval)
			if no then
				self._id = no
................................................................................
			else error('attempted to assign invalid ObjectRef to entity handle') end
		elseif key == 'stack' and self.kind == 'item' then
			hnd:set_item(newval)
		end
	end;
	__index = function(self,key)
		local hnd if self.player then
			hnd = core.get_player_by_name(self._id)
		else
			hnd = core.luaentities[self._id]
		end
		if key == 'online' then
			return hnd ~= nil
		elseif key == 'id' then
			if self.player then return nil
			else return self._id end
		elseif key == 'obj' then
................................................................................
					return maxy-miny, miny
				else return 0 end
			end
		end
	end;
	construct = function(h)
		local kind, id
		if type(h) == 'string' and core.get_player_by_name(h) ~= nil then
			kind = 'player';
			id = h
		elseif core.luaentities[h] then
			kind = 'entity';
			id = h
		else id, kind = fn.identify(h) end

		if not id then
			error('attempted to construct object handle from invalid value')
		end