service_cell.lua 489 B

12345678910111213141516171819202122232425
  1. local skynet = require "skynet"
  2. local service_name = (...)
  3. local init = {}
  4. function init.init(code, ...)
  5. local start_func
  6. skynet.start = function(f)
  7. start_func = f
  8. end
  9. skynet.dispatch("lua", function() error("No dispatch function") end)
  10. local mainfunc = assert(load(code, service_name))
  11. assert(skynet.pcall(mainfunc,...))
  12. if start_func then
  13. start_func()
  14. end
  15. skynet.ret()
  16. end
  17. skynet.start(function()
  18. skynet.dispatch("lua", function(_,_,cmd,...)
  19. init[cmd](...)
  20. end)
  21. end)