/*
* $Id: LuaState.java,v 1.9 2006/12/22 14:06:40 thiago Exp $
* Copyright (C) 2003-2007 Kepler Project.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.keplerproject.luajava;
/**
* LuaState if the main class of LuaJava for the Java developer.
* LuaState is a mapping of most of Lua's C API functions.
* LuaState also provides many other functions that will be used to manipulate
* objects between Lua and Java.
* @author Thiago Ponte
*/
public class LuaState
{
private final static String LUAJAVA_LIB = "luajava-1.1";
final public static Integer LUA_GLOBALSINDEX = new Integer(-10002);
final public static Integer LUA_REGISTRYINDEX = new Integer(-10000);
final public static Integer LUA_TNONE = new Integer(-1);
final public static Integer LUA_TNIL = new Integer(0);
final public static Integer LUA_TBOOLEAN = new Integer(1);
final public static Integer LUA_TLIGHTUSERDATA = new Integer(2);
final public static Integer LUA_TNUMBER = new Integer(3);
final public static Integer LUA_TSTRING = new Integer(4);
final public static Integer LUA_TTABLE = new Integer(5);
final public static Integer LUA_TFUNCTION = new Integer(6);
final public static Integer LUA_TUSERDATA = new Integer(7);
final public static Integer LUA_TTHREAD = new Integer(8);
/**
* Specifies that an unspecified (multiple) number of return arguments
* will be returned by a call.
*/
final public static Integer LUA_MULTRET = new Integer(-1);
/*
* error codes for `lua_load' and `lua_pcall'
*/
/**
* a runtime error.
*/
final public static Integer LUA_ERRRUN = new Integer(1);
/**
*
*/
final public static Integer LUA_YIELD = new Integer(2);
/**
* syntax error during pre-compilation.
*/
final public static Integer LUA_ERRSYNTAX = new Integer(3);
/**
* memory allocation error. For such errors, Lua does not call
* the error handler function.
*/
final public static Integer LUA_ERRMEM = new Integer(4);
/**
* error while running the error handler function.
*/
final public static Integer LUA_ERRERR = new Integer(5);
/**
* Opens the library containing the luajava API
*/
static
{
System.loadLibrary(LUAJAVA_LIB);
}
private CPtr luaState;
private int stateId;
/**
* Constructor to instance a new LuaState and initialize it with LuaJava's functions
* @param stateId
*/
protected LuaState(int stateId)
{
luaState = _open();
luajava_open(luaState, stateId);
this.stateId = stateId;
}
/**
* Receives a existing state and initializes it
* @param luaState
*/
protected LuaState(CPtr luaState)
{
this.luaState = luaState;
this.stateId = LuaStateFactory.insertLuaState(this);
luajava_open(luaState, stateId);
}
/**
* Closes state and removes the object from the LuaStateFactory
*/
public synchronized void close()
{
LuaStateFactory.removeLuaState(stateId);
_close(luaState);
this.luaState = null;
}
/**
* Returns <code>true</code> if state is closed.
*/
public synchronized boolean isClosed()
{
return luaState == null;
}
/**
* Return the long representing the LuaState pointer
* @return long
*/
public long getCPtrPeer()
{
return (luaState != null)? luaState.getPeer() : 0;
}
/********************* Lua Native Interface *************************/
private synchronized native CPtr _open();
private synchronized native void _close(CPtr ptr);
private synchronized native CPtr _newthread(CPtr ptr);
// Stack manipulation
private synchronized native int _getTop(CPtr ptr);
private synchronized native void _setTop(CPtr ptr, int idx);
private synchronized native void _pushValue(CPtr ptr, int idx);
private synchronized native void _remove(CPtr ptr, int idx);
private synchronized native void _insert(CPtr ptr, int idx);
private synchronized native void _replace(CPtr ptr, int idx);
private synchronized native int _checkStack(CPtr ptr, int sz);
private synchronized native void _xmove(CPtr from, CPtr to, int n);
// Access functions
private synchronized native int _isNumber(CPtr ptr, int idx);
private synchronized native int _isString(CPtr ptr, int idx);
private synchronized native int _isCFunction(CPtr ptr, int idx);
private synchronized native int _isUserdata(CPtr ptr, int idx);
private synchronized native int _type(CPtr ptr, int idx);
private synchronized native String _typeName(CPtr ptr, int tp);
private synchronized native int _equal(CPtr ptr, int idx1, int idx2);
private synchronized native int _rawequal(CPtr ptr, int idx1, int idx2);
private synchronized native int _lessthan(CPtr ptr, int idx1, int idx2);
private synchronized native double _toNumber(CPtr ptr, int idx);
private synchronized native int _toInteger(CPtr ptr, int idx);
private synchronized native int _toBoolean(CPtr ptr, int idx);
private synchronized native String _toString(CPtr ptr, int idx);
private synchronized native int _objlen(CPtr ptr, int idx);
private synchronized native CPtr _toThread(CPtr ptr, int idx);
// Push functions
private synchronized native void _pushNil(CPtr ptr);
private synchronized native void _pushNumber(CPtr ptr, double number);
private synchronized native void _pushInteger(CPtr ptr, int integer);
private synchronized native void _pushString(CPtr ptr, String str);
private synchronized native void _pushString(CPtr ptr, byte[] bytes, int n);
private synchronized native void _pushBoolean(CPtr ptr, int bool);
// Get functions
private synchronized native void _getTable(CPtr ptr, int idx);
private synchronized native void _getField(CPtr ptr, int idx, String k);
private synchronized native void _rawGet(CPtr ptr, int idx);
private synchronized native void _rawGetI(CPtr ptr, int idx, int n);
private synchronized native void _createTable(CPtr ptr, int narr, int nrec);
private synchronized native int _getMetaTable(CPtr ptr, int idx);
private synchronized native void _getFEnv(CPtr ptr, int idx);
// Set functions
private synchronized native void _setTable(CPtr ptr, int idx);
private synchronized native void _setField(CPtr ptr, int idx, String k);
private synchronized native void _rawSet(CPtr ptr, int idx);
private synchronized native void _rawSetI(CPtr ptr, int idx, int n);
private synchronized native int _setMetaTable(CPtr ptr, int idx);
private synchronized native int _setFEnv(CPtr ptr, int idx);
private synchronized native void _call(CPtr ptr, int nArgs, int nResults);
private synchronized native int _pcall(CPtr ptr, int nArgs, int Results, int errFunc);
// Coroutine Functions
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Lua in Android (106个子文件)
resources.ap_ 11KB
LuaInAndroidDemo.apk 110KB
luajava.c 98KB
lparser.c 36KB
lstrlib.c 23KB
lvm.c 23KB
lapi.c 22KB
lcode.c 21KB
lgc.c 20KB
loadlib.c 19KB
lauxlib.c 17KB
lbaselib.c 17KB
ldebug.c 16KB
ltable.c 16KB
ldo.c 15KB
liolib.c 13KB
llex.c 12KB
lua.c 10KB
ldblib.c 10KB
ltablib.c 7KB
loslib.c 6KB
lmathlib.c 6KB
lstate.c 6KB
lobject.c 5KB
print.c 5KB
luac.c 5KB
lundump.c 5KB
lfunc.c 5KB
ldump.c 3KB
lstring.c 3KB
lopcodes.c 3KB
lmem.c 2KB
ltm.c 2KB
lzio.c 2KB
linit.c 765B
proguard.cfg 1KB
LuaState.class 21KB
LuaObject.class 9KB
LuaJavaAPI.class 8KB
LuaDemoActivity.class 4KB
Console.class 2KB
FileHelper.class 2KB
LuaInvocationHandler.class 2KB
LuaStateFactory.class 2KB
JavaFunction.class 1KB
LuaDemoActivity$Value.class 678B
LuaException.class 669B
CPtr.class 633B
R.class 459B
R$string.class 412B
R$drawable.class 385B
R$layout.class 379B
R$attr.class 325B
.classpath 280B
classes.dex 37KB
luajava.h 28KB
luaconf.h 22KB
lua.h 11KB
lobject.h 8KB
lopcodes.h 8KB
lauxlib.h 6KB
lstate.h 5KB
lgc.h 3KB
lcode.h 3KB
llimits.h 2KB
lparser.h 2KB
llex.h 2KB
ldo.h 2KB
lzio.h 2KB
lmem.h 1KB
ltable.h 1KB
lvm.h 1KB
lfunc.h 1KB
ldebug.h 1KB
lualib.h 1KB
ltm.h 1018B
lundump.h 890B
lstring.h 814B
lapi.h 262B
package.html 2KB
package.html 2KB
LuaState.java 30KB
LuaJavaAPI.java 14KB
LuaObject.java 12KB
FileHelper.java 5KB
LuaStateFactory.java 3KB
JavaFunction.java 3KB
Console.java 3KB
LuaDemoActivity.java 3KB
LuaInvocationHandler.java 3KB
CPtr.java 2KB
LuaException.java 2KB
R.java 635B
lua_t1.lua 368B
Makefile 6KB
Android.mk 650B
icon.png 4KB
icon.png 3KB
icon.png 2KB
org.eclipse.jdt.core.prefs 208B
共 106 条
- 1
- 2
资源评论
- msdgw2017-01-06好东西,值得下载
- jemii2013-02-05这个很好 很有帮助 感谢楼主
linfs123
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 福袋点点.apk
- Lengyel E. - Foundations of Game Engine Development(卷一卷二合集).zip
- ### 词向量的介绍、使用技巧和优缺点的文章
- 基于STM32F103CBT6单片机GC65+MP2625+CC1101 GPSTrack模块板硬件(原理图+PCB)工程文件
- ### 通道处理过程模拟概念、优缺点和使用技巧
- ### MyBatis动态SQL介绍说明、使用技巧和优缺点
- 上传下载仿163网盘无刷新文件上传 for Jsp-fileupload-jsp.rar
- VMware Workstation业界非常稳定且安全的桌面虚拟机软件-计算机上运行多个操作系统,支持Windows、DOS等
- 基于STM8L101F3P6单片机+LY2508A33P+CC1100遥控器硬件(原理图+PCB)工程文件.zip
- 上传下载WAP图铃下载系统-unimg.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功