일부 기능을 위해 일부 루아 스크립트를 호출하는 C++ (레거시) 응용 프로그램이 있습니다.루아는 내 C++ 공유 라이브러리를로드하지만 종속 공유 라이브러리는로드하지 않습니다.
이제 루아 스크립트에서 호출해야하는 새로운 C++ 라이브러리를 작성하고 있습니다.
#include <lua.hpp>
extern "C" {
static int isquare(lua_State *L){ /* Internal name of func */
return 1; /* One return value */
}
static int icube(lua_State *L){ /* Internal name of func */
return 1; /* One return value */
}
/* Register this file's functions with the
* luaopen_libraryname() function, where libraryname
* is the name of the compiled .so output. In other words
* it's the filename (but not extension) after the -o
* in the cc command.
*
* So for instance, if your cc command has -o power.so then
* this function would be called luaopen_power().
*
* This function should contain lua_register() commands for
* each function you want available from Lua.
*
*/
int luaopen_power(lua_State *L){
printf("before power open");
lua_register(
L, /* Lua state variable */
"square", /* func name as known in Lua */
isquare /* func name in this file */
);
lua_register(L,"cube",icube);
printf("after power register");
return 0;
}
}
g++ -Wall -shared -fPIC -o power.so -I/usr/include/lua5.1 hellofunc.cpp -lstdc++
필자는 링크 용 파일을 언급하지 않았다.
하지만이 power.so는 런타임에 lua-5.1.so가 필요합니다.
이제는 Lua52가 컴파일 된 C++ 레거시 애플리케이션이 있습니다.
그리고 어떤 작업에는 alert.lua가 호출됩니다.
package.cpath = package.cpath .. ";/usr/lib64/power.so"
package.cpath = package.cpath .. ";/usr/lib64/liblua-5.1.so"
require("power")
참고 : power.so로드 루아는 Power.so가 컴파일
lua5.2에서 실행 lua5.1
에 따라 달라집니다 그리고 난 오류를 얻을
undefined symbol: lua_setfield'
이 버전이 동일해야합니까?
누군가이 문제에 관해 밝힐 수 있습니까?
EDIT : lua52.so로 power.so를 컴파일하면 lua 스크립트와 C++ 응용 프로그램이 비정상적으로 중단됩니다.
power.so를 빌드하는 동안 -llua52를 언급하지 않으면 런타임에 정의되지 않은 기호를 말하는 동안 오류가 발생합니다.
편집 : 기타 설명 :
C++ 응용 프로그램 .exe가 있습니다. (samplecpp) lua 5.2 라이브러리와 함께 빌드 된 .dll/.sh도 있으므로 lua뿐만 아니라 다른 기능도 제공합니다. (luaplugin.so)
이 luaplugin.so는 구성된 모든 lua 스크립트를 호출 할 수 있습니다. 루아 스크립트에서 함수를 호출하고 실행합니다.
이제 다른 C++ 모듈에 연결할 Lua 스크립트가 있습니다.
C++ 모듈 (.so는 lua52.so에 의존성이 있습니다.) 나는 루아 스크립트에서로드해야하기 때문에 등록을 위해 루아 함수를 사용합니다.
그러나 런타임에 samplecpp가 lua 스크립트를 실행하고 luascript가 C++ .so를 요구할 때 C++ .so에서 사용되는 루아 함수에 대한 미해결 오류가 발생합니다.
어떻게하면 samplecpp 자체에서 사용할 수있는 루아 함수를 참조 할 수 있습니까?