@@ -204,8 +204,7 @@ using a scripting language to process requests.
204
204
-- The `t` argument is the table that was returned by the _conf function.
205
205
-- All information needed to generate this handler _must_ be contained in this
206
206
-- table. It is bad form to reach for global variables at this stage.
207
- function route_myhello_start (t , ctx )
208
- local fgen = mcp .funcgen_new ()
207
+ function route_myhello_start (t , ctx , fgen )
209
208
-- not adding any children for this function.
210
209
211
210
-- We pass in the argument table to the function generator directly here,
@@ -214,9 +213,6 @@ function route_myhello_start(t, ctx)
214
213
-- `stats proxyfuncs`
215
214
-- `f` is the function to call when we need a new slot made.
216
215
fgen :ready ({ a = t , n = ctx :label (), f = route_myhello_f })
217
-
218
- -- make sure to return the generator we just made
219
- return fgen
220
216
end
221
217
222
218
-- This is now the function that will be called every time we need a new slot.
@@ -250,8 +246,7 @@ register_route_handlers({
250
246
Another example for formatting the ` _start ` function, using more advanced
251
247
lua syntax:
252
248
``` lua
253
- function route_myhello_start (t , ctx )
254
- local fgen = mcp .funcgen_new ()
249
+ function route_myhello_start (t , ctx , fgen )
255
250
local msg = string.format (" SERVER_ERROR %s\r\n " , a .msg )
256
251
257
252
fgen :ready ({ n = ctx :label (), f = function (rctx , a )
@@ -269,8 +264,6 @@ function route_myhello_start(t, ctx)
269
264
return msg
270
265
end
271
266
end })
272
-
273
- return fgen
274
267
end
275
268
```
276
269
@@ -318,14 +311,12 @@ local function route_direct_f(rctx, handle)
318
311
end
319
312
end
320
313
321
- function route_direct_start (t , ctx )
322
- local fgen = mcp .funcgen_new ()
314
+ function route_direct_start (t , ctx , fgen )
323
315
-- t.child has been translated into something we can use here.
324
316
-- At this point we reference it into a handle we can later route to.
325
317
-- Handles must be generated once and are reused for every slot generated.
326
318
local handle = fgen :new_handle (t .child )
327
319
fgen :ready ({ a = handle , n = ctx :label (), f = route_direct_f })
328
- return fgen
329
320
end
330
321
```
331
322
0 commit comments