コード例 #1
0
 // -- JavaFunction methods
 @Override
 public int invoke(LuaState luaState) {
   LuaList luaList = (LuaList) luaState.toJavaObjectRaw(1);
   if (!luaState.isNumber(2)) {
     throw new LuaRuntimeException(
         String.format("attempt to read list with %s accessor", luaState.typeName(2)));
   }
   int index = luaState.toInteger(2);
   luaState.pushJavaObject(luaList.getList().get(index - 1));
   return 1;
 }
コード例 #2
0
 // -- JavaFunction methods
 @Override
 public int invoke(LuaState luaState) {
   LuaList luaList = (LuaList) luaState.toJavaObjectRaw(1);
   if (!luaState.isNumber(2)) {
     throw new LuaRuntimeException(
         String.format("attempt to write list with %s accessor", luaState.typeName(2)));
   }
   int index = luaState.toInteger(2);
   Object value = luaState.toJavaObject(3, Object.class);
   if (value != null) {
     int size = luaList.getList().size();
     if (index - 1 != size) {
       luaList.getList().set(index - 1, value);
     } else {
       luaList.getList().add(value);
     }
   } else {
     luaList.getList().remove(index - 1);
   }
   return 0;
 }