inject d test/inject_fuck.lua  -- d 是服务的 handle

拿 simpledb.lua 举例,修改如下

 local skynet = require "skynet"
require "skynet.manager" -- import skynet.register
local db = {} local command = {} local i =
local str = "abc"
local t = {} function command.fuck()
return i, str, t
end skynet.info_func(function()
return command.fuck()
end) function command.GET(key)
return db[key]
end function command.SET(key, value)
local last = db[key]
db[key] = value
return last
end skynet.start(function()
skynet.dispatch("lua", function(session, address, cmd, ...)
local f = command[string.upper(cmd)]
if f then
skynet.ret(skynet.pack(f(...)))
else
error(string.format("Unknown command %s", tostring(cmd)))
end
end)
skynet.register "SIMPLEDB"
end)

添加了 fuck 函数,并设置 info_func。

设置 info_func 主要用来在 debug console 中方便用 info d 来查看 inject 的结果

下面是 inject_fuck.lua

 if not _P then
print "inject error!"
return
end local function getuv(f)
local i =
local ups = {}
while true do
local name, value = debug.getupvalue(f, i)
if not name then
break
end
ups[name] = { i, value }
i = i +
end
return ups
end local function uvjoin(f, old_f, old_uv)
local i =
while true do
local name, value = debug.getupvalue(f, i)
if not name then
break
end
if old_uv[name] then
debug.upvaluejoin(f, i, old_f, old_uv[name][])
end
i = i +
end
end local command = _P.lua.command local func = command.fuck
local old_uv = getuv(func)
for k,v in pairs(old_uv) do
print(k,v[])
end print(" --- ") local t
local i
local str
function command.fuck()
return str, t, i
end uvjoin(command.fuck, func, old_uv)
-- debug.setupvalue( command.fuck, 1, 35 )

1. 取出原 fuck 函数的所有 upvalue

2. 然后关联到新的 fuck 函数

_P 内存的 key/value 其实就是 skynet.lua 里 14 行 proto 中的 name 和 dispatch 的 upvalue

 local c = require "skynet.core"
local tostring = tostring
local tonumber = tonumber
local coroutine = coroutine
local assert = assert
local pairs = pairs
local pcall = pcall local profile = require "profile" local coroutine_resume = profile.resume
local coroutine_yield = profile.yield local proto = {}
local skynet = {
-- read skynet.h
PTYPE_TEXT = ,
PTYPE_RESPONSE = ,
PTYPE_MULTICAST = ,
PTYPE_CLIENT = ,
PTYPE_SYSTEM = ,
PTYPE_HARBOR = ,
PTYPE_SOCKET = ,
PTYPE_ERROR = ,
PTYPE_QUEUE = , -- used in deprecated mqueue, use skynet.queue instead
PTYPE_DEBUG = ,
PTYPE_LUA = ,
PTYPE_SNAX = ,
} ---

再看 simpledb.lua 的例子,文件中 disptch 的 upvalue 有两个,command 和 skynet

所以 _P.lua.command 就是文件中的 command,_P.lua.skynet 就是 skynet

在 debug console 用 inject 命令时要格外小心。。

skynet inject address file.lua的更多相关文章

  1. skynet 控制台管理使用技巧

    skynet 自带了一个控制台服务.能够非常方便获取和调试 skynet 执行数据,并且能够热更新代码,所以.弄明确skynet控制台管理能够让你更好地使用skynet,甚至改进这个控制台服务.以满足 ...

  2. skynet debug console 使用

    预读 关于如何使用 skynet 可以参考 wiki 文档 更多实战内容见 https://www.lanqiao.cn/courses/2770 优惠码:2CZ2UA5u 环境测试搭建 使用示例代码 ...

  3. [转]Skynet之斗转星移 - 将控制权交给Lua

      Skynet之斗转星移 - 将控制权交给Lua http://www.outsky.org/code/skynet-lua.html Sep 7, 2014 在我看来,Skynet的一个重要优势是 ...

  4. 第6月第19天 lua动态链接库(luaopen_*函数的使用) skynet

    1. 给这个测试库取名为dylib,它包含一个函数add.lua中这样使用: local dylib = require "dylib.test"    local c = dyl ...

  5. skynet newservice API参考

    local skynet = require("skynet") skynet.start(start_func) c服务snlua启动后执行的第一个lua文件里面的主逻辑必定是s ...

  6. 白话skynet第一篇

    当你走过一个坐在自己店门前的杂货商面前.走过一个吸着烟斗的守门人面前,走过一个马车夫面前时,请你给我描绘一下这个杂货商.守门人和马车夫,他们的姿态,他们的外貌,要用画家那样的细节描绘出他们的精神本质, ...

  7. skynet1.0阅读笔记2_skynet的消息投递skynet.call

    为了了解 skynet.call 的调用过程,需要先看看 skynet的队列是如何把包分到不同工作线程的.看下图 查看 global_queue 的skynet_globalmq_push和skyne ...

  8. Skynet服务器框架(八) 任务和消息调度机制

    引言: 在我看来,消息和任务调度应该是skynet的核心,整个skynet框架的核心其实就是一个消息管理系统.在skynet中可以把每个功能都当做一个服务,整个skynet工程在执行过程中会创建很多个 ...

  9. skynet源码阅读<5>--协程调度模型

    注:为方便理解,本文贴出的代码部分经过了缩减或展开,与实际skynet代码可能会有所出入.    作为一个skynet actor,在启动脚本被加载的过程中,总是要调用skynet.start和sky ...

随机推荐

  1. svn 修改原来包名的方法和会报的错误

    SVN E200009 which is not part of the commit; both sides of the move must be committed together 在svn上 ...

  2. Linux日志文件总管——logrotate

    日志文件包含了关于系统中发生的事件的有用信息,在排障过程中或者系统性能分析时经常被用到.对于忙碌的服务器,日志文件大小会增长极快,服务器会很快消耗磁盘空间,这成了个问题.除此之外,处理一个单个的庞大日 ...

  3. Spring框架简介

    1.发明者:Rod Johnson 2.轮子理论推崇者: 2.1 轮子理论:不用重复发明轮子 2.2 IT行业:直接只用写好的代码 3.Spring框架宗旨:不重新发明技术,让原有技术使用起来更加方便 ...

  4. 33、iOS10 由于权限问题导致崩溃的大坑

    控制台报忠告: This app has crashed because it attempted to access privacy-sensitive data without a usage d ...

  5. 2019.01.22 SCU4444 Travel(最短路+bfs)

    传送门 题意简述:给出一张nnn个点的完全图,有mmm条边边权为aaa其余点边权为bbb,问从111到nnn的最短路. 思路:分类讨论一波即可. (1,n)(1,n)(1,n)的边权为aaa,那么只用 ...

  6. 快速创建一个 Servlet 项目(2)

    1. 新建一个 webapp 参考 http://www.cnblogs.com/zno2/p/5909019.html 2.调整jdk版本 修改 pom.xml 文件,将jdk 调整为适当的版本,比 ...

  7. MFC载入JPG图片

    ## 1.定义画图函数 HRESULT CIPCamDlg::draw(char *lpImageFile, HWND hWnd, int nScrWidth, int nScrHeight) { H ...

  8. (转)本地搭建环境wamp下提示不支持GD库的解决方法

    转自:http://www.zzdp.net/local-wamp-gd GD库是什么?GD库,是php处理图形的扩展库,GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片. ...

  9. hihocoder#1631 : Cats and Fish

    Description There are many homeless cats in PKU campus. They are all happy because the students in t ...

  10. POJ2139--Six Degrees of Cowvin Bacon(最简单Floyd)

    The cows have been making movies lately, so they are ready to play a variant of the famous game &quo ...