aboutsummaryrefslogtreecommitdiff
path: root/luaT
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2015-06-22 19:01:29 +0800
committerDeterminant <ted.sybil@gmail.com>2015-06-22 19:01:29 +0800
commit2497fd9e7a0fae5ee4887890d7a312e0e08a93b8 (patch)
tree382f97575bd2df9ee6abb1662b11b279fc22d72b /luaT
parent196e9b48a3541caccdffc5743001cced70667091 (diff)
major change: use luarocks to manage project
Diffstat (limited to 'luaT')
-rw-r--r--luaT/README.md239
-rw-r--r--luaT/luaT.c1079
-rw-r--r--luaT/luaT.h111
3 files changed, 0 insertions, 1429 deletions
diff --git a/luaT/README.md b/luaT/README.md
deleted file mode 100644
index 6e9cf0d..0000000
--- a/luaT/README.md
+++ /dev/null
@@ -1,239 +0,0 @@
-<a name="luat.dok"/>
-# Lua Torch C API #
-
-luaT provides an API to interface Lua and C in Torch packages. It defines a
-concept of _classes_ to Lua for Torch, and provides a mechanism to easily
-handle these Lua classes from C.
-
-It additionally provides few functions that `luaL` should have defined, and
-defines several functions similar to `luaL` ones for better type error printing when using
-`luaT` classes.
-
-<a name="luat.memory.dok"/>
-## Memory functions ##
-
-Classical memory allocation functions which generate a Lua error in case of
-problem.
-
-<a name="luaT_alloc"/>
-### void* luaT_alloc(lua_State *L, long size) ###
-
-Allocates `size` bytes, and return a pointer on the allocated
-memory. A Lua error will be generated if running out of memory.
-
-<a name="luaT_realloc"/>
-### void* luaT_realloc(lua_State *L, void *ptr, long size) ###
-
-Realloc `ptr` to `size` bytes. `ptr` must have been previously
-allocated with [luaT_alloc](#luaT_alloc) or
-[luaT_realloc](#luaT_realloc), or the C `malloc` or `realloc`
-functions. A Lua error will be generated if running out of memory.
-
-<a name="luaT_free"/>
-### void luaT_free(lua_State *L, void *ptr) ###
-
-Free memory allocated at address `ptr`. The memory must have been
-previously allocated with [luaT_alloc](#luaT_alloc) or
-[luaT_realloc](#luaT_realloc), or the C `malloc` or `realloc`
-functions.
-
-<a name="luat.classcreate"/>
-## Class creation and basic handling ##
-
-A `luaT` class is basically either a Lua _table_ or _userdata_ with
-an appropriate _metatable_. This appropriate metatable is created with
-[luaT_newmetatable](#luaT_newmetatable). Contrary to luaL userdata
-functions, luaT mechanism handles inheritance. If the class inherit from
-another class, then the metatable will itself have a metatable
-corresponding to the _parent metatable_: the metatables are cascaded
-according to the class inheritance. Multiple inheritance is not supported.
-
-<a name="luat.operatoroverloading"/>
-### Operator overloading ###
-
-The metatable of a `luaT` object contains `Lua` operators like
-`__index`, `__newindex`, `__tostring`, `__add`
-(etc...). These operators will respectively look for `__index__`,
-`__newindex__`, `__tostring__`, `__add__` (etc...) in the
-metatable. If found, the corresponding function or value will be returned,
-else a Lua error will be raised.
-
-If one wants to provide `__index__` or `__newindex__` in the
-metaclass, these operators must follow a particular scheme:
-
- * `__index__` must either return a value _and_ `true` or return `false` only. In the first case, it means `__index__` was able to handle the given argument (for e.g., the type was correct). The second case means it was not able to do anything, so `__index` in the root metatable can then try to see if the metaclass contains the required value.
-
- * `__newindex__` must either return `true` or `false`. As for `__index__`, `true` means it could handle the argument and `false` not. If not, the root metatable `__newindex` will then raise an error if the object was a userdata, or apply a rawset if the object was a Lua table.
-
-Other metaclass operators like `__tostring__`, `__add__`, etc... do not have any particular constraint.
-
-<a name="luat_newmetatable"/>
-### const char* luaT_newmetatable(lua_State *L, const char *tname, const char *parenttname, lua_CFunction constructor, lua_CFunction destructor, lua_CFunction factory) ###
-
-This function creates a new metatable, which is the Lua way to define a new
-object class. As for `luaL_newmetatable`, the metatable is registered in
-the Lua registry table, with the key `tname`. In addition, `tname` is
-also registered in the Lua registry, with the metatable as key (the
-typename of a given object can be thus easily retrieved).
-
-The class name `tname` must be of the form `modulename.classname`. The module name
-If not NULL, `parenttname` must be a valid typename corresponding to the
-parent class of the new class.
-
-If not NULL, `constructor`, a function `new` will be added to the metatable, pointing to this given function. The constructor might also
-be called through `modulename.classname()`, which is an alias setup by `luaT_metatable`.
-
-If not NULL, `destructor` will be called when garbage collecting the object.
-
-If not NULL, `factory` must be a Lua C function creating an empty object
-instance of the class. This functions are used in Torch for serialization.
-
-Note that classes can be partly defined in C and partly defined in Lua:
-once the metatable is created in C, it can be filled up with additional
-methods in Lua.
-
-The return value is the value returned by [luaT_typenameid](#luat_typenameid).
-
-<a name="luat_pushmetatable"/>
-### int luaT_pushmetatable(lua_State *L, const name *tname) ###
-
-Push the metatable with type name `tname` on the stack, it `tname` is a
-valid Torch class name (previously registered with luaT_newmetatable).
-
-On success, returns 1. If `tname` is invalid, nothing is pushed and it
-returns 0.
-
-<a name="luat_typenameid"/>
-### const char* luaT_typenameid(lua_State *L, const char *tname) ###
-
-If `tname` is a valid Torch class name, then returns a unique string (the
-contents will be the same than `tname`) pointing on the string registered
-in the Lua registry. This string is thus valid as long as Lua is
-running. The returned string shall not be freed.
-
-If `tname` is an invalid class name, returns NULL.
-
-<a name="luat_typename"/>
-### const char* luaT_typename(lua_State *L, int ud) ###
-
-Returns the typename of the object at index `ud` on the stack. If it is
-not a valid Torch object, returns NULL.
-
-<a name="luat_pushudata"/>
-### void luaT_pushudata(lua_State *L, void *udata, const char *tname) ###
-
-Given a C structure `udata`, push a userdata object on the stack with
-metatable corresponding to `tname`. Obviously, `tname` must be a valid
-Torch name registered with [luaT_newmetatable](#luat_newmetatable).
-
-<a name="luat_toudata"/>
-### void *luaT_toudata(lua_State *L, int ud, const char *tname) ###
-
-Returns a pointer to the original C structure previously pushed on the
-stack with [luaT_pushudata](#luat_pushudata), if the object at index
-`ud` is a valid Torch class name. Returns NULL otherwise.
-
-<a name="luat_isudata"/>
-### int luaT_isudata(lua_State *L, int ud, const char *tname) ###
-
-Returns 1 if the object at index `ud` on the stack is a valid Torch class name `tname`.
-Returns 0 otherwise.
-
-<a name="luat_getfield"/>
-### Checking fields of a table ###
-
-This functions check that the table at the given index `ud` on the Lua
-stack has a field named `field`, and that it is of the specified type.
-These function raises a Lua error on failure.
-
-<a name="luat_getfieldcheckudata"/>
-## void *luaT_getfieldcheckudata(lua_State *L, int ud, const char *field, const char *tname) ##
-
-Checks that the field named `field` of the table at index `ud` is a
-Torch class name `tname`. Returns the pointer of the C structure
-previously pushed on the stack with [luaT_pushudata](#luat_pushudata) on
-success. The function raises a Lua error on failure.
-
-<a name="luat_getfieldchecklightudata"/>
-## void *luaT_getfieldchecklightudata(lua_State *L, int ud, const char *field) ##
-
-Checks that the field named `field` of the table at index `ud` is a
-lightuserdata. Returns the lightuserdata pointer on success. The function
-raises a Lua error on failure.
-
-<a name="luat_getfieldcheckint"/>
-## int luaT_getfieldcheckint(lua_State *L, int ud, const char *field) ##
-
-Checks that the field named `field` of the table at index `ud` is an
-int. Returns the int value pointer on success. The function raises a Lua
-error on failure.
-
-<a name="luat_getfieldcheckstring"/>
-## const char* luaT_getfieldcheckstring(lua_State *L, int ud, const char *field) ##
-
-Checks that the field named `field` of the table at index `ud` is a
-string. Returns a pointer to the string on success. The function raises a
-Lua error on failure.
-
-<a name="luat_getfieldcheckboolean"/>
-## int luaT_getfieldcheckboolean(lua_State *L, int ud, const char *field) ##
-
-Checks that the field named `field` of the table at index `ud` is a
-boolean. On success, returns 1 if the boolean is `true`, 0 if it is
-`false`. The function raises a Lua error on failure.
-
-<a name="luat_getfieldchecktable"/>
-## void luaT_getfieldchecktable(lua_State *L, int ud, const char *field) ##
-
-Checks that the field named `field` of the table at index `ud` is a
-table. On success, push the table on the stack. The function raises a Lua
-error on failure.
-
-<a name="luat_typerror"/>
-### int luaT_typerror(lua_State *L, int ud, const char *tname) ###
-
-Raises a `luaL_argerror` (and returns its value), claiming that the
-object at index `ud` on the stack is not of type `tname`. Note that
-this function does not check the type, it only raises an error.
-
-<a name="luat_checkboolean"/>
-### int luaT_checkboolean(lua_State *L, int ud) ###
-
-Checks that the value at index `ud` is a boolean. On success, returns 1
-if the boolean is `true`, 0 if it is `false`. The function raises a Lua
-error on failure.
-
-<a name="luat_optboolean"/>
-### int luaT_optboolean(lua_State *L, int ud, int def) ###
-
-Checks that the value at index `ud` is a boolean. On success, returns 1
-if the boolean is `true`, 0 if it is `false`. If there is no value at
-index `ud`, returns `def`. In any other cases, raises an error.
-
-<a name="luat_registeratname"/>
-### void luaT_registeratname(lua_State *L, const struct luaL_Reg *methods, const char *name) ###
-
-This function assume a table is on the stack. It creates a table field
-`name` in the table (if this field does not exist yet), and fill up
-`methods` in this table field.
-
-<a name="luat_classrootname"/>
-### const char *luaT_classrootname(const char *tname) ###
-
-Assuming `tname` is of the form `modulename.classname`, returns
-`classname`. The returned value shall not be freed. It is a pointer
-inside `tname` string.
-
-<a name="luat_classmodulename"/>
-### const char *luaT_classmodulename(const char *tname) ###
-
-Assuming `tname` is of the form `modulename.classname`, returns
-`modulename`. The returned value shall not be freed. It is valid until the
-next call to `luaT_classrootname`.
-
-<a name="luat_stackdump"/>
-### void luaT_stackdump(lua_State *L) ###
-
-This function print outs the state of the Lua stack. It is useful for debug
-purposes.
-
diff --git a/luaT/luaT.c b/luaT/luaT.c
deleted file mode 100644
index 7b85ce3..0000000
--- a/luaT/luaT.c
+++ /dev/null
@@ -1,1079 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-
-#include "luaT.h"
-
-void* luaT_alloc(lua_State *L, long size)
-{
- void *ptr;
-
- if(size == 0)
- return NULL;
-
- if(size < 0)
- luaL_error(L, "$ Torch: invalid memory size -- maybe an overflow?");
-
- ptr = malloc(size);
- if(!ptr)
- luaL_error(L, "$ Torch: not enough memory: you tried to allocate %dGB. Buy new RAM!", size/1073741824);
-
- return ptr;
-}
-
-void* luaT_realloc(lua_State *L, void *ptr, long size)
-{
- if(!ptr)
- return(luaT_alloc(L, size));
-
- if(size == 0)
- {
- luaT_free(L, ptr);
- return NULL;
- }
-
- if(size < 0)
- luaL_error(L, "$ Torch: invalid memory size -- maybe an overflow?");
-
- ptr = realloc(ptr, size);
- if(!ptr)
- luaL_error(L, "$ Torch: not enough memory: you tried to reallocate %dGB. Buy new RAM!", size/1073741824);
- return ptr;
-}
-
-void luaT_free(lua_State *L, void *ptr)
-{
- free(ptr);
-}
-
-void luaT_stackdump(lua_State *L)
-{
- int i;
- const char *tname = NULL;
- int top = lua_gettop(L);
- for(i = 1; i <= top; i++)
- {
- int t = lua_type(L, i);
- printf("%3d. ", i);
- switch(t)
- {
- case LUA_TSTRING:
- printf("'%s'", lua_tostring(L,i));
- break;
- case LUA_TBOOLEAN:
- printf(lua_toboolean(L, i) ? "true" : "false");
- break;
- case LUA_TNUMBER:
- printf("%g", lua_tonumber(L,i));
- break;
- case LUA_TUSERDATA:
- tname = luaT_typename(L, i);
- printf("userdata %lx [%s]", (long)lua_topointer(L, i), (tname ? tname : "not a Torch object"));
- break;
- case 10:
- tname = luaT_typename(L, i);
- printf("cdata %lx [%s]", (long)lua_topointer(L, i), (tname ? tname : "not a Torch object"));
- break;
- case LUA_TTABLE:
- lua_pushvalue(L, i);
- lua_rawget(L, LUA_REGISTRYINDEX);
- if(lua_isstring(L, -1))
- tname = lua_tostring(L, -1); /*luaT_typenameid(L, lua_tostring(L, -1)); */
- else
- tname = NULL;
- lua_pop(L, 1);
- if(tname)
- printf("metatable [%s]", tname);
- else
- {
- tname = luaT_typename(L, i);
- printf("table %lx [%s]", (long)lua_topointer(L, i), (tname ? tname : "not a Torch object"));
- }
- break;
- default:
- printf("Lua object type: %s", lua_typename(L,t));
- break;
- }
- printf("\n");
- }
- printf("---------------------------------------------\n");
-}
-
-/* metatable operator methods */
-static int luaT_mt__index(lua_State *L);
-static int luaT_mt__newindex(lua_State *L);
-static int luaT_mt__tostring(lua_State *L);
-static int luaT_mt__add(lua_State *L);
-static int luaT_mt__sub(lua_State *L);
-static int luaT_mt__mul(lua_State *L);
-static int luaT_mt__div(lua_State *L);
-static int luaT_mt__mod(lua_State *L);
-static int luaT_mt__pow(lua_State *L);
-static int luaT_mt__unm(lua_State *L);
-static int luaT_mt__concat(lua_State *L);
-static int luaT_mt__len(lua_State *L);
-static int luaT_mt__eq(lua_State *L);
-static int luaT_mt__lt(lua_State *L);
-static int luaT_mt__le(lua_State *L);
-static int luaT_mt__call(lua_State *L);
-
-/* Constructor-metatable methods */
-static int luaT_cmt__call(lua_State *L);
-static int luaT_cmt__newindex(lua_State *L);
-
-const char* luaT_newmetatable(lua_State *L, const char *tname, const char *parenttname,
- lua_CFunction constructor, lua_CFunction destructor, lua_CFunction factory)
-{
- lua_pushcfunction(L, luaT_lua_newmetatable);
- lua_pushstring(L, tname);
- (parenttname ? lua_pushstring(L, parenttname) : lua_pushnil(L));
- (constructor ? lua_pushcfunction(L, constructor) : lua_pushnil(L));
- (destructor ? lua_pushcfunction(L, destructor) : lua_pushnil(L));
- (factory ? lua_pushcfunction(L, factory) : lua_pushnil(L));
- lua_call(L, 5, 1);
- return luaT_typenameid(L, tname);
-}
-
-int luaT_pushmetatable(lua_State *L, const char *tname)
-{
- lua_getfield(L, LUA_REGISTRYINDEX, tname);
- if(lua_isnil(L, -1))
- {
- lua_pop(L, 1);
- return 0;
- }
- return 1;
-}
-
-const char *luaT_typenameid(lua_State *L, const char *tname)
-{
- if(luaT_pushmetatable(L, tname))
- {
- const char *tnameid = NULL;
- lua_rawget(L, LUA_REGISTRYINDEX);
- if(lua_isstring(L, -1))
- tnameid = lua_tostring(L, -1);
- lua_pop(L, 1); /* the string/nil */
- return tnameid;
- }
- return NULL;
-}
-
-static const char cdataname[] = ""
- "local _, ffi = pcall(require, 'ffi')\n"
- "if ffi then\n"
- " local id2name = {}\n"
- " return function(cdata, name)\n"
- " local id = tonumber(ffi.typeof(cdata))\n"
- " if id then\n"
- " if name then\n"
- " id2name[id] = name\n"
- " return name\n"
- " else\n"
- " return rawget(id2name, id)\n"
- " end\n"
- " end\n"
- " return nil\n"
- " end\n"
- "else\n"
- " return function() end\n"
- "end\n";
-
-static const char* luaT_cdataname(lua_State *L, int ud, const char *tname)
-{
- lua_pushstring(L, "__cdataname");
- lua_rawget(L, LUA_REGISTRYINDEX);
- if(lua_isnil(L,-1))
- {
- lua_pop(L, 1);
-
- if(luaL_dostring(L, cdataname)) /* did something go wrong? */
- luaL_error(L, "internal error (could not load cdataname): %s", lua_tostring(L, -1));
-
- lua_pushstring(L, "__cdataname");
- lua_pushvalue(L, -2);
- lua_rawset(L, LUA_REGISTRYINDEX);
- }
- if(!lua_isfunction(L, -1)) /* should not happen */
- luaL_error(L, "internal error (cdataname is not a function)");
-
- lua_pushvalue(L, ud);
- if(tname)
- lua_pushstring(L, tname);
- if(lua_pcall(L, (tname ? 2 : 1), 1, 0))
- luaL_error(L, "internal error (cdataname): %s", lua_tostring(L, -1));
-
- tname = lua_tostring(L, -1);
- lua_pop(L, 1);
-
- return tname;
-}
-
-const char* luaT_typename(lua_State *L, int ud)
-{
- if(lua_type(L, ud) == 10)
- return luaT_cdataname(L, ud, NULL);
- else if(lua_getmetatable(L, ud))
- {
- const char *tname = NULL;
- lua_rawget(L, LUA_REGISTRYINDEX);
- if(lua_isstring(L, -1))
- tname = lua_tostring(L, -1);
- lua_pop(L, 1); /* the string/nil */
- return tname;
- }
- return NULL;
-}
-
-void luaT_pushudata(lua_State *L, void *udata, const char *tname)
-{
- if(udata)
- {
- void **udata_p = lua_newuserdata(L, sizeof(void*));
- *udata_p = udata;
- if(!luaT_pushmetatable(L, tname))
- luaL_error(L, "Torch internal problem: cannot find metatable for type <%s>", tname);
- lua_setmetatable(L, -2);
- }
- else
- lua_pushnil(L);
-}
-
-void *luaT_toudata(lua_State *L, int ud, const char *tname)
-{
- void **p = lua_touserdata(L, ud);
- if(p != NULL) /* value is a userdata? */
- {
- if(!luaT_pushmetatable(L, tname))
- luaL_error(L, "Torch internal problem: cannot find metatable for type <%s>", tname);
-
- /* initialize the table we want to get the metatable on */
- /* note that we have to be careful with indices, as we just inserted stuff */
- lua_pushvalue(L, (ud < 0 ? ud - 1 : ud));
- while(lua_getmetatable(L, -1)) /* get the next metatable */
- {
- lua_remove(L, -2); /* remove the previous metatable [or object, if first time] */
- if(lua_rawequal(L, -1, -2))
- {
- lua_pop(L, 2); /* remove the two metatables */
- return *p;
- }
- }
- lua_pop(L, 2); /* remove the two metatables */
- }
- return NULL;
-}
-
-int luaT_isudata(lua_State *L, int ud, const char *tname)
-{
- if(luaT_toudata(L, ud, tname))
- return 1;
- else
- return 0;
-}
-
-void *luaT_checkudata(lua_State *L, int ud, const char *tname)
-{
- void *p = luaT_toudata(L, ud, tname);
- if(!p)
- luaT_typerror(L, ud, tname);
- return p;
-}
-
-void *luaT_getfieldcheckudata(lua_State *L, int ud, const char *field, const char *tname)
-{
- void *p;
- lua_getfield(L, ud, field);
- if(lua_isnil(L, -1))
- luaL_error(L, "bad argument #%d (field %s does not exist)", ud, field);
- p = luaT_toudata(L, -1, tname);
- if(!p)
- luaL_error(L, "bad argument #%d (field %s is not a %s)", ud, field, tname);
- return p;
-}
-
-void *luaT_getfieldchecklightudata(lua_State *L, int ud, const char *field)
-{
- void *p;
- lua_getfield(L, ud, field);
- if(lua_isnil(L, -1))
- luaL_error(L, "bad argument #%d (field %s does not exist)", ud, field);
-
- if(!lua_islightuserdata(L, -1))
- luaL_error(L, "bad argument #%d (field %s is not a light userdata)", ud, field);
-
- p = lua_touserdata(L, -1);
-
- return p;
-}
-
-double luaT_getfieldchecknumber(lua_State *L, int ud, const char *field)
-{
- lua_getfield(L, ud, field);
- if(lua_isnil(L, -1))
- luaL_error(L, "bad argument #%d (field %s does not exist)", ud, field);
- if(!lua_isnumber(L, -1))
- luaL_error(L, "bad argument #%d (field %s is not a number)", ud, field);
- return lua_tonumber(L, -1);
-}
-
-int luaT_getfieldcheckint(lua_State *L, int ud, const char *field)
-{
- lua_getfield(L, ud, field);
- if(lua_isnil(L, -1))
- luaL_error(L, "bad argument #%d (field %s does not exist)", ud, field);
- if(!lua_isnumber(L, -1))
- luaL_error(L, "bad argument #%d (field %s is not a number)", ud, field);
- return (int)lua_tonumber(L, -1);
-}
-
-const char* luaT_getfieldcheckstring(lua_State *L, int ud, const char *field)
-{
- lua_getfield(L, ud, field);
- if(lua_isnil(L, -1))
- luaL_error(L, "bad argument #%d (field %s does not exist)", ud, field);
- if(!lua_isstring(L, -1))
- luaL_error(L, "bad argument #%d (field %s is not a string)", ud, field);
- return lua_tostring(L, -1);
-}
-
-int luaT_getfieldcheckboolean(lua_State *L, int ud, const char *field)
-{
- lua_getfield(L, ud, field);
- if(lua_isnil(L, -1))
- luaL_error(L, "bad argument #%d (field %s does not exist)", ud, field);
- if(!lua_isboolean(L, -1))
- luaL_error(L, "bad argument #%d (field %s is not a boolean)", ud, field);
- return lua_toboolean(L, -1);
-}
-
-void luaT_getfieldchecktable(lua_State *L, int ud, const char *field)
-{
- lua_getfield(L, ud, field);
- if(lua_isnil(L, -1))
- luaL_error(L, "bad argument #%d (field %s does not exist)", ud, field);
- if(!lua_istable(L, -1))
- luaL_error(L, "bad argument #%d (field %s is not a table)", ud, field);
-}
-
-/**** type checks as in luaL ****/
-int luaT_typerror(lua_State *L, int ud, const char *tname)
-{
- const char *msg;
- const char *tnameud = luaT_typename(L, ud);
-
- if(!tnameud)
- tnameud = lua_typename(L, ud);
-
- msg = lua_pushfstring(L, "%s expected, got %s",
- tname,
- (tnameud ? tnameud : "unknown object"));
-
- return luaL_argerror(L, ud, msg);
-}
-
-int luaT_checkboolean(lua_State *L, int ud)
-{
- if(!lua_isboolean(L, ud))
- luaT_typerror(L, ud, lua_typename(L, LUA_TBOOLEAN));
- return lua_toboolean(L, ud);
-}
-
-int luaT_optboolean(lua_State *L, int ud, int def)
-{
- if(lua_isnoneornil(L,ud))
- return def;
-
- return luaT_checkboolean(L, ud);
-}
-
-void luaT_registeratname(lua_State *L, const struct luaL_Reg *methods, const char *name)
-{
- int idx = lua_gettop(L);
-
- luaL_checktype(L, idx, LUA_TTABLE);
- lua_pushstring(L, name);
- lua_rawget(L, idx);
-
- if(lua_isnil(L, -1))
- {
- lua_pop(L, 1);
- lua_pushstring(L, name);
- lua_newtable(L);
- lua_rawset(L, idx);
-
- lua_pushstring(L, name);
- lua_rawget(L, idx);
- }
-
- luaL_register(L, NULL, methods);
- lua_pop(L, 1);
-}
-
-
-/* utility functions */
-const char *luaT_classrootname(const char *tname)
-{
- int i;
- int sz = strlen(tname);
-
- for(i = 0; i < sz; i++)
- {
- if(tname[i] == '.')
- return tname+i+1;
- }
- return tname;
-}
-
-/* module_name must be a buffer at least as big as tname
- * return true if the class is part of a module */
-int luaT_classmodulename(const char *tname, char *module_name)
-{
- char chars[] = {'.', '\0'};
- size_t n;
- n = strcspn(tname, chars);
- strncpy(module_name, tname, n);
- module_name[n] = '\0';
- return tname[n] == '.';
-}
-
-/* Lua only functions */
-int luaT_lua_newmetatable(lua_State *L)
-{
- const char* tname = luaL_checkstring(L, 1);
- char module_name[256];
- int is_in_module = 0;
- is_in_module = luaT_classmodulename(tname, module_name);
-
- lua_settop(L, 5);
- luaL_argcheck(L, lua_isnoneornil(L, 2) || lua_isstring(L, 2), 2, "parent class name or nil expected");
- luaL_argcheck(L, lua_isnoneornil(L, 3) || lua_isfunction(L, 3), 3, "constructor function or nil expected");
- luaL_argcheck(L, lua_isnoneornil(L, 4) || lua_isfunction(L, 4), 4, "destructor function or nil expected");
- luaL_argcheck(L, lua_isnoneornil(L, 5) || lua_isfunction(L, 5), 5, "factory function or nil expected");
-
- if(is_in_module)
- lua_getfield(L, LUA_GLOBALSINDEX, module_name);
- else
- lua_pushvalue(L, LUA_GLOBALSINDEX);
- if(!lua_istable(L, 6))
- luaL_error(L, "while creating metatable %s: bad argument #1 (%s is an invalid module name)", tname, module_name);
-
- /* we first create the new metaclass if we have to */
- if(!luaT_pushmetatable(L, tname))
- {
- /* create the metatable */
- lua_newtable(L);
-
- /* registry[name] = metatable */
- lua_pushvalue(L, -1);
- lua_setfield(L, LUA_REGISTRYINDEX, tname);
-
- /* registry[metatable] = tname */
- lua_pushvalue(L, -1);
- lua_pushstring(L, tname);
- lua_rawset(L, LUA_REGISTRYINDEX);
-
- /* __index handling */
- lua_pushcfunction(L, luaT_mt__index);
- lua_setfield(L, -2, "__index");
-
- /* __newindex handling */
- lua_pushcfunction(L, luaT_mt__newindex);
- lua_setfield(L, -2, "__newindex");
-
- /* __typename contains the typename */
- lua_pushstring(L, tname);
- lua_setfield(L, -2, "__typename");
-
- /* __metatable is self */
- lua_pushvalue(L, -1);
- lua_setfield(L, -2, "__metatable");
-
- /* by default, __version equals 1 */
- lua_pushnumber(L, 1);
- lua_setfield(L, -2, "__version");
-
- /* assign default operator functions */
- lua_pushcfunction(L, luaT_mt__tostring);
- lua_setfield(L, -2, "__tostring");
-
- lua_pushcfunction(L, luaT_mt__add);
- lua_setfield(L, -2, "__add");
-
- lua_pushcfunction(L, luaT_mt__sub);
- lua_setfield(L, -2, "__sub");
-
- lua_pushcfunction(L, luaT_mt__mul);
- lua_setfield(L, -2, "__mul");
-
- lua_pushcfunction(L, luaT_mt__div);
- lua_setfield(L, -2, "__div");
-
- lua_pushcfunction(L, luaT_mt__mod);
- lua_setfield(L, -2, "__mod");
-
- lua_pushcfunction(L, luaT_mt__pow);
- lua_setfield(L, -2, "__pow");
-
- lua_pushcfunction(L, luaT_mt__unm);
- lua_setfield(L, -2, "__unm");
-
- lua_pushcfunction(L, luaT_mt__concat);
- lua_setfield(L, -2, "__concat");
-
- lua_pushcfunction(L, luaT_mt__len);
- lua_setfield(L, -2, "__len");
-
- lua_pushcfunction(L, luaT_mt__eq);
- lua_setfield(L, -2, "__eq");
-
- lua_pushcfunction(L, luaT_mt__lt);
- lua_setfield(L, -2, "__lt");
-
- lua_pushcfunction(L, luaT_mt__le);
- lua_setfield(L, -2, "__le");
-
- lua_pushcfunction(L, luaT_mt__call);
- lua_setfield(L, -2, "__call");
- }
-
- /* we assign the parent class if necessary */
- if(!lua_isnoneornil(L, 2))
- {
- if(lua_getmetatable(L, -1))
- luaL_error(L, "class %s has been already assigned a parent class\n", tname);
- else
- {
- const char* parenttname = luaL_checkstring(L, 2);
- if(!luaT_pushmetatable(L, parenttname))
- luaL_error(L, "bad argument #2 (invalid parent class name %s)", parenttname);
- lua_setmetatable(L, -2);
- }
- }
-
- /* register the destructor function */
- if(!lua_isnoneornil(L, 4))
- {
- /* does it exists already? */
- lua_pushstring(L, "__gc");
- lua_rawget(L, -2);
-
- if(lua_isnil(L, -1))
- {
- lua_pop(L, 1); /* pop nil */
- lua_pushstring(L, "__gc");
- lua_pushvalue(L, 4);
- lua_rawset(L, -3);
- }
- else
- luaL_error(L, "%s has been already assigned a destructor", tname);
- }
-
- /* register the factory function */
- if(!lua_isnoneornil(L, 5))
- {
- /* does it exists already? */
- lua_pushstring(L, "__factory");
- lua_rawget(L, -2);
-
- if(lua_isnil(L, -1))
- {
- lua_pop(L, 1); /* pop nil */
- lua_pushstring(L, "__factory");
- lua_pushvalue(L, 5);
- lua_rawset(L, -3);
- }
- else
- luaL_error(L, "%s has been already assigned a factory", tname);
- }
-
- /******** Constructor table and metatable ********/
- lua_pushstring(L, "__constructor");
- lua_rawget(L, -2);
- if(lua_isnil(L, -1))
- {
- lua_pop(L, 1); /* pop nil */
- lua_newtable(L); /* fancy table */
- lua_newtable(L); /* fancy metatable */
-
- lua_pushvalue(L, -3); /* metatable */
- lua_setfield(L, -2, "__index"); /* so we can get the methods */
-
- lua_pushcfunction(L, luaT_cmt__newindex);
- lua_setfield(L, -2, "__newindex"); /* so we add new methods */
-
- lua_pushcfunction(L, luaT_cmt__call);
- lua_setfield(L, -2, "__call"); /* so we can create, we are here for only that */
-
- lua_pushvalue(L, -3);
- lua_setfield(L, -2, "__metatable"); /* redirect to metatable with methods */
-
- lua_setmetatable(L, -2); /* constructor metatable is ... this fancy metatable */
-
- /* set metatable[__constructor] = constructor-metatable */
- lua_pushstring(L, "__constructor");
- lua_pushvalue(L, -2);
- lua_rawset(L, -4);
- }
-
- /* register the constructor function */
- if(!lua_isnoneornil(L, 3))
- {
- /* get constructor metatable */
- lua_getmetatable(L, -1);
-
- /* does it exists already? */
- lua_pushstring(L, "__new");
- lua_rawget(L, -2);
-
- if(lua_isnil(L, -1))
- {
- lua_pop(L, 1); /* pop nil */
- lua_pushstring(L, "__new");
- lua_pushvalue(L, 3);
- lua_rawset(L, -3);
-
- /* set "new" in the metatable too */
- lua_pushstring(L, "new");
- lua_pushvalue(L, 3);
- lua_rawset(L, -5);
- }
- else
- luaL_error(L, "%s has been already assigned a constructor", tname);
-
- /* pop constructor metatable */
- lua_pop(L, 1);
- }
-
- /* module.name = constructor metatable */
- lua_setfield(L, 6, luaT_classrootname(tname));
-
- return 1; /* returns the metatable */
-}
-
-/* Lua only utility functions */
-
-/* add any custom type, provided the object has a metatable */
-int luaT_lua_metatype(lua_State *L)
-{
- if( (lua_gettop(L) != 2) && (lua_gettop(L) != 3) )
- luaL_error(L, "expecting: string table [ctype]");
-
- luaL_checkstring(L, 1);
- luaL_checktype(L, 2, LUA_TTABLE);
-
- if(lua_gettop(L) == 3)
- {
- if(!luaT_cdataname(L, 3, lua_tostring(L, 1)))
- luaL_error(L, "could not register cdata type -- missing ffi library?");
- }
-
- /* registry[name] = metatable */
- lua_pushvalue(L, 1);
- lua_pushvalue(L, 2);
- lua_rawset(L, LUA_REGISTRYINDEX);
-
- /* registry[metatable] = tname */
- lua_pushvalue(L, 2);
- lua_pushvalue(L, 1);
- lua_rawset(L, LUA_REGISTRYINDEX);
-
- return 0;
-}
-
-/* return a userdata from a C pointer */
-/* you are better to know what you are doing */
-int luaT_lua_pushudata(lua_State *L)
-{
- void *udata = NULL;
- const char *tname = luaL_checkstring(L, 2);
-
- if(lua_type(L, 1) == 10)
- udata = *((void**)lua_topointer(L, 1));
- else if(lua_isnumber(L, 1))
- udata = (void*)(long)lua_tonumber(L, 1);
- else
- luaL_argerror(L, 1, "expecting number or cdata");
-
- luaT_pushudata(L, udata, tname);
-
- return 1;
-}
-
-int luaT_lua_factory(lua_State *L)
-{
- const char* tname = luaL_checkstring(L, 1);
- if(luaT_pushmetatable(L, tname) && !lua_isnil(L, -1))
- {
- lua_pushstring(L, "__factory");
- lua_rawget(L, -2);
- }
- else
- {
- lua_pushnil(L);
- }
- return 1;
-}
-
-int luaT_lua_getconstructortable(lua_State *L)
-{
- const char* tname = luaL_checkstring(L, 1);
- if(luaT_pushmetatable(L, tname))
- {
- lua_pushstring(L, "__constructor");
- lua_rawget(L, -2);
- return 1;
- }
- return 0;
-}
-
-
-int luaT_lua_typename(lua_State *L)
-{
- const char* tname = NULL;
- luaL_checkany(L, 1);
- if((tname = luaT_typename(L, 1)))
- {
- lua_pushstring(L, tname);
- return 1;
- }
- return 0;
-}
-
-int luaT_lua_isequal(lua_State *L)
-{
- if(lua_isuserdata(L, 1) && lua_isuserdata(L, 2))
- {
- void **u1, **u2;
- luaL_argcheck(L, luaT_typename(L, 1), 1, "Torch object expected");
- luaL_argcheck(L, luaT_typename(L, 2), 2, "Torch object expected");
-
- u1 = lua_touserdata(L, 1);
- u2 = lua_touserdata(L, 2);
- if(*u1 == *u2)
- lua_pushboolean(L, 1);
- else
- lua_pushboolean(L, 0);
- }
- else if(lua_istable(L, 1) && lua_istable(L, 2))
- lua_pushboolean(L, lua_rawequal(L, 1, 2));
- else
- lua_pushboolean(L, 0);
- return 1;
-}
-
-int luaT_lua_pointer(lua_State *L)
-{
- if(lua_isuserdata(L, 1))
- {
- void **ptr;
- luaL_argcheck(L, luaT_typename(L, 1), 1, "Torch object expected");
- ptr = lua_touserdata(L, 1);
- lua_pushnumber(L, (long)(*ptr));
- return 1;
- }
- else if(lua_istable(L, 1) || lua_isthread(L, 1) || lua_isfunction(L, 1))
- {
- const void* ptr = lua_topointer(L, 1);
- lua_pushnumber(L, (long)(ptr));
- return 1;
- }
- else if(lua_type(L, 1) == 10) /* cdata */
- {
- /* we want the pointer holded by cdata */
- /* not the pointer on the cdata object */
- const void* ptr = *((void**)lua_topointer(L, 1));
- lua_pushnumber(L, (long)(ptr));
- return 1;
- }
- else if(lua_isstring(L, 1))
- {
- const char* ptr = lua_tostring(L, 1);
- lua_pushnumber(L, (long)(ptr));
- return 1;
- }
- else
- luaL_error(L, "Torch object, table, thread, cdata or function expected");
-
- return 0;
-}
-
-int luaT_lua_setenv(lua_State *L)
-{
- if(!lua_isfunction(L, 1) && !lua_isuserdata(L, 1))
- luaL_typerror(L, 1, "function or userdata");
- luaL_checktype(L, 2, LUA_TTABLE);
- lua_setfenv(L, 1);
- return 0;
-}
-
-int luaT_lua_getenv(lua_State *L)
-{
- if(!lua_isfunction(L, 1) && !lua_isuserdata(L, 1))
- luaL_typerror(L, 1, "function or userdata");
- lua_getfenv(L, 1);
- return 1;
-}
-
-int luaT_lua_getmetatable(lua_State *L)
-{
- const char *tname = luaL_checkstring(L, 1);
- if(luaT_pushmetatable(L, tname))
- return 1;
- return 0;
-}
-
-int luaT_lua_version(lua_State *L)
-{
- luaL_checkany(L, 1);
-
- if(lua_type(L, 1) == 10)
- {
- const char *tname = luaT_cdataname(L, 1, NULL);
- if(tname)
- {
- luaT_pushmetatable(L, tname);
- lua_pushstring(L, "__version");
- lua_rawget(L, -2);
- return 1;
- }
- return 0;
- }
- else if(lua_getmetatable(L, 1))
- {
- lua_pushstring(L, "__version");
- lua_rawget(L, -2);
- return 1;
- }
- return 0;
-}
-
-int luaT_lua_setmetatable(lua_State *L)
-{
- const char *tname = luaL_checkstring(L, 2);
- luaL_checktype(L, 1, LUA_TTABLE);
-
- if(!luaT_pushmetatable(L, tname))
- luaL_error(L, "unknown typename %s\n", tname);
- lua_setmetatable(L, 1);
-
- return 1;
-}
-
-/* metatable operator methods */
-static int luaT_mt__index(lua_State *L)
-{
- if(!lua_getmetatable(L, 1))
- luaL_error(L, "critical internal indexing error: no metatable found");
-
- if(!lua_istable(L, -1))
- luaL_error(L, "critical internal indexing error: not a metatable");
-
- /* test for __index__ method first */
- lua_getfield(L, -1, "__index__");
- if(!lua_isnil(L, -1))
- {
- int result;
-
- if(!lua_isfunction(L, -1))
- luaL_error(L, "critical internal indexing error: __index__ is not a function");
-
- lua_pushvalue(L, 1);
- lua_pushvalue(L, 2);
-
- lua_call(L, 2, LUA_MULTRET); /* DEBUG: risque: faut vraiment retourner 1 ou 2 valeurs... */
-
- result = lua_toboolean(L, -1);
- lua_pop(L, 1);
-
- if(result)
- return 1;
-
- /* on the stack: 1. the object 2. the value 3. the metatable */
- /* apparently, __index wants only one element returned */
- /* return lua_gettop(L)-3; */
-
- }
- else
- lua_pop(L, 1); /* remove nil __index__ on the stack */
-
- lua_pushvalue(L, 2);
- lua_gettable(L, -2);
-
- return 1;
-}
-
-static int luaT_mt__newindex(lua_State *L)
-{
- if(!lua_getmetatable(L, 1))
- luaL_error(L, "critical internal indexing error: no metatable found");
-
- if(!lua_istable(L, -1))
- luaL_error(L, "critical internal indexing error: not a metatable");
-
- /* test for __newindex__ method first */
- lua_getfield(L, -1, "__newindex__");
- if(!lua_isnil(L, -1))
- {
- int result;
-
- if(!lua_isfunction(L, -1))
- luaL_error(L, "critical internal indexing error: __newindex__ is not a function");
-
- lua_pushvalue(L, 1);
- lua_pushvalue(L, 2);
- lua_pushvalue(L, 3);
-
- lua_call(L, 3, 1); /* DEBUG: risque: faut vraiment retourner qqch */
-
- result = lua_toboolean(L, -1);
- lua_pop(L, 1);
-
- if(result)
- return 0;
- }
- else
- lua_pop(L, 1); /* remove nil __newindex__ on the stack */
-
- lua_pop(L, 1); /* pop the metatable */
- if(lua_istable(L, 1))
- lua_rawset(L, 1);
- else
- luaL_error(L, "the class %s cannot be indexed", luaT_typename(L, 1));
-
- return 0;
-}
-
-/* note: check dans metatable pour ca, donc necessaire */
-#define MT_DECLARE_OPERATOR(NAME, NIL_BEHAVIOR) \
- int luaT_mt__##NAME(lua_State *L) \
- { \
- if(!lua_getmetatable(L, 1)) \
- luaL_error(L, "internal error in __" #NAME ": no metatable"); \
- \
- lua_getfield(L, -1, "__" #NAME "__"); \
- if(lua_isnil(L, -1)) \
- { \
- NIL_BEHAVIOR; \
- } \
- else \
- { \
- if(lua_isfunction(L, -1)) \
- { \
- lua_insert(L, 1); /* insert function */ \
- lua_pop(L, 1); /* remove metatable */ \
- lua_call(L, lua_gettop(L)-1, LUA_MULTRET); /* we return the result of the call */ \
- return lua_gettop(L); \
- } \
- /* we return the thing the user left in __tostring__ */ \
- } \
- return 0; \
- }
-
-MT_DECLARE_OPERATOR(tostring,
- lua_pushstring(L, luaT_typename(L, 1));
- return 1;)
-MT_DECLARE_OPERATOR(add, luaL_error(L, "%s has no addition operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(sub, luaL_error(L, "%s has no substraction operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(mul, luaL_error(L, "%s has no multiplication operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(div, luaL_error(L, "%s has no division operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(mod, luaL_error(L, "%s has no modulo operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(pow, luaL_error(L, "%s has no power operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(unm, luaL_error(L, "%s has no negation operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(concat, luaL_error(L, "%s has no concat operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(len, luaL_error(L, "%s has no length operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(eq,
- lua_settop(L, 2);
- lua_pushcfunction(L, luaT_lua_isequal);
- lua_insert(L, 1);
- lua_call(L, 2, 1);
- return 1;)
-MT_DECLARE_OPERATOR(lt, luaL_error(L, "%s has no lower than operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(le, luaL_error(L, "%s has no lower or equal than operator", luaT_typename(L, 1)))
-MT_DECLARE_OPERATOR(call, luaL_error(L, "%s has no call operator", luaT_typename(L, 1)))
-
-
-/* constructor metatable methods */
-int luaT_cmt__call(lua_State *L)
-{
- if(!lua_istable(L, 1))
- luaL_error(L, "internal error in __call: not a constructor table");
-
- if(!lua_getmetatable(L, 1))
- luaL_error(L, "internal error in __call: no metatable available");
-
- lua_pushstring(L, "__new");
- lua_rawget(L, -2);
-
- if(lua_isnil(L, -1))
- luaL_error(L, "no constructor available");
-
- lua_remove(L, 1); /* remove constructor atable */
- lua_insert(L, 1); /* insert constructor */
- lua_pop(L, 1); /* remove fancy metatable */
-
- lua_call(L, lua_gettop(L)-1, LUA_MULTRET);
- return lua_gettop(L);
-}
-
-int luaT_cmt__newindex(lua_State *L)
-{
- if(!lua_istable(L, 1))
- luaL_error(L, "internal error in __newindex: not a constructor table");
-
- if(!lua_getmetatable(L, 1))
- luaL_error(L, "internal error in __newindex: no metatable available");
-
- lua_pushstring(L, "__metatable");
- lua_rawget(L, -2);
-
- if(!lua_istable(L, -1))
- luaL_error(L, "internal error in __newindex: no metaclass available");
-
- lua_insert(L, 2);
- lua_pop(L, 1); /* remove the metatable over the constructor table */
-
- lua_rawset(L, -3);
-
- return 0;
-}
-
-/******************** deprecated functions ********************/
-int luaT_pushmetaclass(lua_State *L, const char *tname)
-{
- return luaT_pushmetatable(L, tname);
-}
-
-const char* luaT_id(lua_State *L, int ud)
-{
- return luaT_typename(L, ud);
-}
-
-const char* luaT_id2typename(lua_State *L, const char *id)
-{
- return id;
-}
-
-const char* luaT_typename2id(lua_State *L, const char *tname)
-{
- return luaT_typenameid(L, tname);
-}
-
-int luaT_getmetaclass(lua_State *L, int index)
-{
- return lua_getmetatable(L, index);
-}
-
-const char* luaT_checktypename2id(lua_State *L, const char *tname)
-{
- const char* id = luaT_typenameid(L, tname);
- if(!id)
- luaL_error(L, "unknown class <%s>", tname);
- return id;
-}
-
-void luaT_registeratid(lua_State *L, const struct luaL_Reg *methods, const char *id)
-{
- luaT_registeratname(L, methods, id);
-}
-
-/**************************************************************/
diff --git a/luaT/luaT.h b/luaT/luaT.h
deleted file mode 100644
index 5e8dd2f..0000000
--- a/luaT/luaT.h
+++ /dev/null
@@ -1,111 +0,0 @@
-#ifndef LUAT_UTILS_INC
-#define LUAT_UTILS_INC
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include <lua.h>
-#include <lauxlib.h>
-#ifdef __cplusplus
-}
-#endif
-
-#ifndef LUA_EXTERNC
-# ifdef __cplusplus
-# define LUA_EXTERNC extern "C"
-# else
-# define LUA_EXTERNC extern
-# endif
-#endif
-
-#ifdef _MSC_VER
-# define DLL_EXPORT __declspec(dllexport)
-# define DLL_IMPORT __declspec(dllimport)
-# ifdef luaT_EXPORTS
-# define LUAT_API LUA_EXTERNC DLL_EXPORT
-# else
-# define LUAT_API LUA_EXTERNC DLL_IMPORT
-# endif
-#else
-# define DLL_EXPORT
-# define DLL_IMPORT
-# define LUAT_API LUA_EXTERNC
-#endif
-
-
-/* C functions */
-
-LUAT_API void* luaT_alloc(lua_State *L, long size);
-LUAT_API void* luaT_realloc(lua_State *L, void *ptr, long size);
-LUAT_API void luaT_free(lua_State *L, void *ptr);
-
-LUAT_API const char* luaT_newmetatable(lua_State *L, const char *tname, const char *parenttname,
- lua_CFunction constructor, lua_CFunction destructor, lua_CFunction factory);
-
-LUAT_API int luaT_pushmetatable(lua_State *L, const char *tname);
-
-LUAT_API const char* luaT_typenameid(lua_State *L, const char *tname);
-LUAT_API const char* luaT_typename(lua_State *L, int ud);
-
-LUAT_API void luaT_pushudata(lua_State *L, void *udata, const char *tname);
-LUAT_API void *luaT_toudata(lua_State *L, int ud, const char *tname);
-LUAT_API int luaT_isudata(lua_State *L, int ud, const char *tname);
-LUAT_API void *luaT_checkudata(lua_State *L, int ud, const char *tname);
-
-LUAT_API void *luaT_getfieldcheckudata(lua_State *L, int ud, const char *field, const char *tname);
-LUAT_API void *luaT_getfieldchecklightudata(lua_State *L, int ud, const char *field);
-LUAT_API double luaT_getfieldchecknumber(lua_State *L, int ud, const char *field);
-LUAT_API int luaT_getfieldcheckint(lua_State *L, int ud, const char *field);
-LUAT_API const char* luaT_getfieldcheckstring(lua_State *L, int ud, const char *field);
-LUAT_API int luaT_getfieldcheckboolean(lua_State *L, int ud, const char *field);
-LUAT_API void luaT_getfieldchecktable(lua_State *L, int ud, const char *field);
-
-LUAT_API int luaT_typerror(lua_State *L, int ud, const char *tname);
-
-LUAT_API int luaT_checkboolean(lua_State *L, int ud);
-LUAT_API int luaT_optboolean(lua_State *L, int ud, int def);
-
-LUAT_API void luaT_registeratname(lua_State *L, const struct luaL_Reg *methods, const char *name);
-
-/* utility functions */
-LUAT_API const char *luaT_classrootname(const char *tname);
-LUAT_API int luaT_classmodulename(const char *tname, char *module_name);
-
-/* debug */
-LUAT_API void luaT_stackdump(lua_State *L);
-
-/* Lua functions */
-LUAT_API int luaT_lua_newmetatable(lua_State *L);
-LUAT_API int luaT_lua_factory(lua_State *L);
-LUAT_API int luaT_lua_getconstructortable(lua_State *L);
-LUAT_API int luaT_lua_typename(lua_State *L);
-LUAT_API int luaT_lua_isequal(lua_State *L);
-LUAT_API int luaT_lua_pointer(lua_State *L);
-LUAT_API int luaT_lua_setenv(lua_State *L);
-LUAT_API int luaT_lua_getenv(lua_State *L);
-LUAT_API int luaT_lua_getmetatable(lua_State *L);
-LUAT_API int luaT_lua_version(lua_State *L);
-LUAT_API int luaT_lua_setmetatable(lua_State *L);
-LUAT_API int luaT_lua_metatype(lua_State *L);
-LUAT_API int luaT_lua_pushudata(lua_State *L);
-
-/* deprecated functions */
-/* ids have been replaced by string names to identify classes */
-/* comments show what function (that you should use) they call now */
-#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
-#define LUAT_DEPRECATED __attribute__((__deprecated__))
-#elif defined(_MSC_VER)
-#define LUAT_DEPRECATED __declspec(deprecated)
-#else
-#define LUAT_DEPRECATED
-#endif
-
-LUAT_API LUAT_DEPRECATED int luaT_pushmetaclass(lua_State *L, const char *tname); /* same as luaT_pushmetatable */
-LUAT_API LUAT_DEPRECATED const char* luaT_id(lua_State *L, int ud); /* same as luaT_typename */
-LUAT_API LUAT_DEPRECATED const char* luaT_id2typename(lua_State *L, const char *id); /* same as luaT_typenameid */
-LUAT_API LUAT_DEPRECATED const char* luaT_typename2id(lua_State *L, const char*); /* same as luaT_typenameid */
-LUAT_API LUAT_DEPRECATED int luaT_getmetaclass(lua_State *L, int index); /* same as luaT_getmetatable */
-LUAT_API LUAT_DEPRECATED const char* luaT_checktypename2id(lua_State *L, const char *tname); /* same as luaT_typenameid */
-LUAT_API LUAT_DEPRECATED void luaT_registeratid(lua_State *L, const struct luaL_Reg *methods, const char *id); /* same as luaT_registeratname */
-
-#endif
2191' href='#n2191'>2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761