@@ -91,7 +91,6 @@ macro ( install_lua_executable _name _source )
9191 find_package ( Lua51 REQUIRED )
9292 include_directories ( ${LUA_INCLUDE_DIR} )
9393
94- get_filename_component ( _source_name ${_source} NAME_WE )
9594 set ( _wrapper ${CMAKE_CURRENT_BINARY_DIR} /${_name} .c )
9695 set ( _code
9796"// Not so simple executable wrapper for Lua apps
@@ -141,7 +140,7 @@ static int report (lua_State *L, int status) {
141140if (status && !lua_isnil(L, -1)) {
142141 const char *msg = lua_tostring(L, -1)\;
143142 if (msg == NULL) msg = \" (error object is not a string)\"\;
144- l_message(\" ${_name } \" , msg)\;
143+ l_message(\" ${_source_name } \" , msg)\;
145144 lua_pop(L, 1)\;
146145}
147146return status\;
@@ -184,10 +183,25 @@ L=lua_open()\;
184183lua_gc(L, LUA_GCSTOP, 0)\;
185184luaL_openlibs(L)\;
186185lua_gc(L, LUA_GCRESTART, 0)\;
187- getargs(L, argv, 0)\;
186+ int narg = getargs(L, argv, 0)\;
188187lua_setglobal(L, \" arg\" )\;
189- // _PROGDIR global is only available when loadlib_rel.c is used in Lua
190- int status = luaL_dostring(L, \" return dofile ( (_PROGDIR or '.') .. '/${_source_name} .lua')\" )\;
188+
189+ // Script
190+ char script[500] = \" ./${_source_name} .lua\"\;
191+ lua_getglobal(L, \" _PROGDIR\" )\;
192+ if (lua_isstring(L, -1)) {
193+ sprintf( script, \" %s/${_source_name} .lua\" , lua_tostring(L, -1))\;
194+ }
195+ lua_pop(L, 1)\;
196+
197+ // Run
198+ int status = luaL_loadfile(L, script)\;
199+ lua_insert(L, -(narg+1))\;
200+ if (status == 0)
201+ status = docall(L, narg, 0)\;
202+ else
203+ lua_pop(L, narg)\;
204+
191205report(L, status)\;
192206lua_close(L)\;
193207return status\;
@@ -377,13 +391,15 @@ return dofile '${TESTFILEABS}'
377391 if ( ${ARGC} GREATER 1 )
378392 set ( _testcurrentdir ${ARGV1} )
379393 get_filename_component ( TESTCURRENTDIRABS ${_testcurrentdir} ABSOLUTE )
380- set ( TESTWRAPPERSOURCE
381- "require 'lfs'
382- lfs.chdir('${TESTCURRENTDIRABS} ' )
383- ${TESTWRAPPERSOURCE} " )
394+ # note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter.
395+ #old:
396+ # set ( TESTWRAPPERSOURCE
397+ #"require 'lfs'; lfs.chdir('${TESTCURRENTDIRABS}' )
398+ #${TESTWRAPPERSOURCE}" )
399+ set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS} " )
384400 endif ()
385401 file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE} )
386- add_test ( NAME ${TESTFILEBASE} COMMAND ${LUA} ${TESTWRAPPER} $<CONFIGURATION > )
402+ add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${ LUA} ${TESTWRAPPER} $<CONFIGURATION > )
387403 endif ()
388404 # see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake
389405endmacro ()
0 commit comments