依賴包(附件有下載): java
包名 |
類型 |
操做系統 |
luajava-1.1.jar |
jar |
ALL |
libluajava-1.1.so |
.so |
linux |
luajava-1.1.dll |
.dll |
windows |
windows:
將luajava-1.1.dll拷貝到java.libary.path目錄(經過System.getProperty("java.library.path")能夠知道)
linux:
將libluajava-1.1.so拷貝到java.libary.path目錄(經過System.getProperty("java.library.path")能夠知道)
若是linux有問題,則按如下操做從新編譯.so文件
1.編譯&安裝Lua
tar -zxvf lua-5.1.5.tar.gz
cd lua-5.1.5
make linux install
注:64位系統須要先編輯src/Makefile,在CFLAGS上添加-fPIC。
2.編譯與安裝Luajava
tar -zxvf luajava-1.1.tar.gz
cd luajava-1.1
修改 config文件,添加JAVA_HOME=/broadtech/javaweb/jdk1.6.0_25
make
3.部署。
將編譯好的libluajava-1.1.so拷貝到java.libary.path目錄(經過System.getProperty("java.library.path")能夠知道),
luajava-1.1.jar拷貝到$JAVA_HOME\jre\lib\ext目錄
四、重啓項目
注:LuaJava1.1缺乏了JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushInteger (JNIEnv * env , jobject jobj , jobject cptr , jint number) 方法的實現,編譯前可編輯src/c/luajava.c加入如下代碼實現再make
linux
-
-
-
-
-
- JNIEXPORT void JNICALL Java_org_keplerproject_luajava_LuaState__1pushInteger
- (JNIEnv * env , jobject jobj , jobject cptr , jint number)
- {
- lua_State * L = getStateFromCPtr( env , cptr );
-
- lua_pushinteger( L, ( lua_Integer ) number );
- }
LuaUtil.java web
-
-
-
-
-
- public class LuaUtil {
- public static List<String> PUBLIC_LUA_FILES = new ArrayList<String>();
- public static Logger logger = Logger.getLogger(LuaUtil.class);
-
- static {
-
-
- }
-
-
-
-
- public static String execLuaFunc(String lua,String funcName,String value){
-
- logger.debug("java.library.path:"+System.getProperty("java.library.path"));
-
- LuaState L = LuaStateFactory.newLuaState();
-
- L.openLibs();
-
-
- if(!PUBLIC_LUA_FILES.isEmpty()){
- for(int i=0;i<PUBLIC_LUA_FILES.size();i++){
- L.LdoFile(PUBLIC_LUA_FILES.get(i));
- }
- }
-
-
- L.LdoString(lua);
-
- L.getField(LuaState.LUA_GLOBALSINDEX, funcName);
-
- L.pushString(value);
-
-
- L.call(1, 1);
-
-
- L.setField(LuaState.LUA_GLOBALSINDEX, "RESULT");
- LuaObject lobj = L.getLuaObject("RESULT");
-
-
- String res = lobj.getString();
- L.close();
-
- if(res == null) return "";
- return res;
- }
- }