diff --git a/src/lua/ULuaCore.pas b/src/lua/ULuaCore.pas index 05fd5849e..b2bfdb17e 100644 --- a/src/lua/ULuaCore.pas +++ b/src/lua/ULuaCore.pas @@ -192,7 +192,7 @@ function TLua_CustomPanic (L: Plua_State): integer; cdecl; can be called with more than one parameter to require some modules at once. e.g.: require('math', 'Usdx.Log') modules are loaded from right to left - unlike standard require the module tables are not returned + the module table of the last module is returned the standard require function in _require is called by this function } function TLua_CustomRequire(L: PLua_State): integer; cdecl; @@ -957,18 +957,27 @@ function TLua_CustomPanic (L: Plua_State): integer; cdecl; can be called with more than one parameter to require some modules at once. e.g.: require('math', 'Usdx.Log') modules are loaded from right to left - unlike standard require the module tables are not returned + the module table of the last module is returned the standard require function in _require is called by this function } function TLua_CustomRequire(L: PLua_State): integer; cdecl; begin - // no results + // how many values to return (this is to become 1 for the last iteration) Result := 0; // move through parameters - while (lua_getTop(L) >= 1) do + while ((lua_getTop(L) >= 1) and (Result = 0)) do begin + if lua_getTop(L) = 1 then + begin + // this is the last in the list of modules to be loaded + // prepare to return its table + Result := 1; + end; + + // make sure there is room on the stack for the require function lua_checkstack(L,1); + // get luas require function lua_getglobal(L, PChar('_require')); @@ -976,7 +985,8 @@ function TLua_CustomRequire(L: PLua_State): integer; cdecl; lua_insert(L, -2); // call it with next param (function + param are poped from stack) - lua_call(L, 1, 0); + // all return values are ignored (Result is set to 0) except for the last iteration (Result is set to 1) + lua_call(L, 1, Result); end; end;