-- инжекция свего кода в биндер актора

local function inj_main(func_name,flag,fn,narg)
	if not _G.bind_stalker.actor_binder["_"..fn] then
		_G.bind_stalker.actor_binder["_"..fn] = {}
		if narg==1 then
			_G.bind_stalker.actor_binder["_"..fn][1] = _G.bind_stalker.actor_binder[fn]
			_G.bind_stalker.actor_binder[fn] = function(...)
				for _,f in pairs (_G.bind_stalker.actor_binder["_"..fn]) do f(...) end end
		else
			_G.bind_stalker.actor_binder[fn.."_"] = _G.bind_stalker.actor_binder[fn] or function()end
			_G.bind_stalker.actor_binder[fn] = function(...) local arg={...}
				_G.bind_stalker.actor_binder[fn.."_"](...)
				for _,f in pairs (_G.bind_stalker.actor_binder["_"..fn]) do
					f(arg[narg])
				end
			end
		end
	end
	_G.bind_stalker.actor_binder["_"..fn][func_name] = loadstring('return _G["'..string.gsub(flag and func_name or "_","%.",'"]["')..'"]')()
end

function inj_on_info(func_name,flag)
	inj_main(func_name,flag,"info_callback",3)
end

function inj_update(func_name,flag)
	inj_main(func_name,flag,"update",1)
end

function inj_take(func_name,flag)
	inj_main(func_name,flag,"on_item_take",2)
end

function inj_drop(func_name,flag)
	inj_main(func_name,flag,"on_item_drop",2)
end

function inj_save(func_name,flag)
	inj_main(func_name,flag,"save",1)
end

function inj_load(func_name,flag)
	inj_main(func_name,flag,"net_spawn",1)
end

function inj_on_use(func_name,flag)
	local use_fname = "use_object" -- метод биндера актора,подвешенный на callback.use_object
	if _G.bind_stalker.actor_binder[use_fname] then
		inj_main(func_name,flag,use_fname,2)
	else
			-- добавляем юз
		_G.bind_stalker.actor_binder["_"..use_fname] = {}
		_G.bind_stalker.actor_binder["_"..use_fname][func_name] = loadstring('return _G["'..string.gsub(flag and func_name or "_","%.",'"]["')..'"]')()
		_G.bind_stalker.actor_binder[use_fname] =
			function(...) local arg={...}
			for _,f in pairs (_G.bind_stalker.actor_binder["_"..use_fname]) do
				f(arg[2])
			end
		end
			--добавляем в реинит колбек на юз
		_G.actor_reinit = _G.bind_stalker.actor_binder.reinit
		_G.bind_stalker.actor_binder.reinit = function(...)
				_G.actor_reinit(...)
				local arg={...}
				local binder = arg[1]
				binder.object:set_callback(callback.use_object, binder[use_fname], binder)
		end
	end
end