ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

lauxlib.cpp

Go to the documentation of this file.
00001 /*
00002 ** Auxiliary functions for building Lua libraries
00003 ** See Copyright Notice in lua.h
00004 */
00005 
00006 
00007 /* Please Notice: This file uses only the official API of Lua
00008 ** Any function declared here could be written as an application
00009 ** function. With care, these functions can be used by other libraries.
00010 */
00011 
00012 #include "engines/grim/lua/lauxlib.h"
00013 #include "engines/grim/lua/lua.h"
00014 #include "engines/grim/lua/luadebug.h"
00015 #include "engines/grim/lua/lmem.h"
00016 
00017 namespace Grim {
00018 
00019 void luaL_argerror(int32 numarg, const char *extramsg) {
00020     const char *funcname;
00021     lua_getobjname(lua_stackedfunction(0), &funcname);
00022     if (!funcname)
00023         funcname = "???";
00024     if (!extramsg)
00025         luaL_verror("bad argument #%d to function `%.50s'", numarg, funcname);
00026     else
00027         luaL_verror("bad argument #%d to function `%.50s' (%.100s)", numarg, funcname, extramsg);
00028 }
00029 
00030 const char *luaL_check_string(int32 numArg) {
00031     lua_Object o = lua_getparam(numArg);
00032     luaL_arg_check(lua_isstring(o), numArg, "string expected");
00033     return lua_getstring(o);
00034 }
00035 
00036 const char *luaL_opt_string(int32 numArg, const char *def) {
00037     return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : luaL_check_string(numArg);
00038 }
00039 
00040 float luaL_check_number(int32 numArg) {
00041     lua_Object o = lua_getparam(numArg);
00042     luaL_arg_check(lua_isnumber(o), numArg, "number expected");
00043     return lua_getnumber(o);
00044 }
00045 
00046 float luaL_opt_number(int32 numArg, float def) {
00047     return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : luaL_check_number(numArg);
00048 }  
00049 
00050 lua_Object luaL_tablearg(int32 arg) {
00051     lua_Object o = lua_getparam(arg);
00052     luaL_arg_check(lua_istable(o), arg, "table expected");
00053     return o;
00054 }
00055 
00056 lua_Object luaL_functionarg(int32 arg) {
00057     lua_Object o = lua_getparam(arg);
00058     luaL_arg_check(lua_isfunction(o), arg, "function expected");
00059     return o;
00060 }
00061 
00062 lua_Object luaL_nonnullarg(int32 numArg) {
00063     lua_Object o = lua_getparam(numArg);
00064     luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
00065     return o;
00066 }
00067 
00068 luaL_libList *list_of_libs = nullptr;
00069 
00070 void luaL_addlibtolist(luaL_reg *l, int32 n) {
00071     luaL_libList *list = (luaL_libList *)luaM_malloc(sizeof(luaL_libList));
00072     list->list = l;
00073     list->number = n;
00074     list->next = list_of_libs;
00075     list_of_libs = list;
00076 }
00077 
00078 void lua_removelibslists() {
00079     luaL_libList *list = list_of_libs;
00080     while (list) {
00081         luaL_libList *nextList = list->next;
00082         luaM_free(list);
00083         list = nextList;
00084     }
00085     list_of_libs = nullptr;
00086 }
00087 
00088 void luaL_openlib(luaL_reg *l, int32 n) {
00089     int32 i;
00090     lua_open();  // make sure lua is already open
00091     for (i = 0; i < n; i++)
00092         lua_register(l[i].name, l[i].func);
00093     luaL_addlibtolist(l, n);
00094 }
00095 
00096 void luaL_verror(const char *fmt, ...) {
00097     char buff[500];
00098     va_list argp;
00099 
00100     va_start(argp, fmt);
00101     vsprintf(buff, fmt, argp);
00102     va_end(argp);
00103     lua_error(buff);
00104 }
00105 
00106 } // end of namespace Grim


Generated on Sat Feb 23 2019 05:01:07 for ResidualVM by doxygen 1.7.1
curved edge   curved edge