@@ -204,8 +204,7 @@ using a scripting language to process requests.
204204-- The `t` argument is the table that was returned by the _conf function.
205205-- All information needed to generate this handler _must_ be contained in this
206206-- 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 )
209208 -- not adding any children for this function.
210209
211210 -- We pass in the argument table to the function generator directly here,
@@ -214,9 +213,6 @@ function route_myhello_start(t, ctx)
214213 -- `stats proxyfuncs`
215214 -- `f` is the function to call when we need a new slot made.
216215 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
220216end
221217
222218-- This is now the function that will be called every time we need a new slot.
@@ -250,8 +246,7 @@ register_route_handlers({
250246Another example for formatting the ` _start ` function, using more advanced
251247lua syntax:
252248``` lua
253- function route_myhello_start (t , ctx )
254- local fgen = mcp .funcgen_new ()
249+ function route_myhello_start (t , ctx , fgen )
255250 local msg = string.format (" SERVER_ERROR %s\r\n " , a .msg )
256251
257252 fgen :ready ({ n = ctx :label (), f = function (rctx , a )
@@ -269,8 +264,6 @@ function route_myhello_start(t, ctx)
269264 return msg
270265 end
271266 end })
272-
273- return fgen
274267end
275268```
276269
@@ -318,14 +311,12 @@ local function route_direct_f(rctx, handle)
318311 end
319312end
320313
321- function route_direct_start (t , ctx )
322- local fgen = mcp .funcgen_new ()
314+ function route_direct_start (t , ctx , fgen )
323315 -- t.child has been translated into something we can use here.
324316 -- At this point we reference it into a handle we can later route to.
325317 -- Handles must be generated once and are reused for every slot generated.
326318 local handle = fgen :new_handle (t .child )
327319 fgen :ready ({ a = handle , n = ctx :label (), f = route_direct_f })
328- return fgen
329320end
330321```
331322
0 commit comments