mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
remote object
This commit is contained in:
24
service/testrobj.lua
Normal file
24
service/testrobj.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local skynet = require "skynet"
|
||||
|
||||
skynet.remote_service()
|
||||
|
||||
local obj = { id = 0 }
|
||||
|
||||
function obj.hello()
|
||||
return "Hello"
|
||||
end
|
||||
|
||||
function obj:inc()
|
||||
self.id = self.id + 1
|
||||
return self.id
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
skynet.remote_create(obj)
|
||||
local root = skynet.remote_root()
|
||||
print(root.echo("hello"))
|
||||
root.register("test",obj)
|
||||
local qobj = root.query "test"
|
||||
print(qobj.hello())
|
||||
print(qobj:inc())
|
||||
end)
|
||||
Reference in New Issue
Block a user