@@ -121,9 +121,9 @@ static int checkRegisteredModules(lua_State* L, const char* path)
121
121
int lua_requirecont (lua_State* L, int status)
122
122
{
123
123
// Number of stack arguments present before this continuation is called.
124
- const int numStackArgs = 2 ;
124
+ const int numStackArgs = lua_tointeger (L, 1 ) ;
125
125
const int numResults = lua_gettop (L) - numStackArgs;
126
- const char * cacheKey = luaL_checkstring (L, 2 );
126
+ const char * cacheKey = luaL_checkstring (L, numStackArgs );
127
127
128
128
if (numResults > 1 )
129
129
luaL_error (L, " module must return a single value" );
@@ -152,6 +152,8 @@ int lua_requirecont(lua_State* L, int status)
152
152
153
153
int lua_requireinternal (lua_State* L, const char * requirerChunkname)
154
154
{
155
+ int stackTop = lua_gettop (L);
156
+
155
157
// If modifying the state of the stack, please update numStackArgs in the
156
158
// lua_requirecont continuation function.
157
159
@@ -171,10 +173,14 @@ int lua_requireinternal(lua_State* L, const char* requirerChunkname)
171
173
if (resolvedRequire.status == ResolvedRequire::Status::Cached)
172
174
return 1 ;
173
175
174
- // (1) path, (2) cacheKey
176
+ // (1) path, ..., cacheKey
175
177
lua_pushstring (L, resolvedRequire.cacheKey .c_str ());
176
178
177
- int numArgsBeforeLoad = lua_gettop (L);
179
+ // Insert number of arguments before the continuation to check the results.
180
+ int numArgsBeforeLoad = stackTop + 2 ;
181
+ lua_pushinteger (L, numArgsBeforeLoad);
182
+ lua_insert (L, 1 );
183
+
178
184
int numResults = lrc->load (L, ctx, path, resolvedRequire.chunkname .c_str (), resolvedRequire.contents .c_str ());
179
185
if (numResults == -1 )
180
186
{
0 commit comments