aboutsummaryrefslogtreecommitdiff
path: root/src/lua/libraries/luax/luax.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-23 12:23:58 +0800
committerchai <chaifix@163.com>2018-10-23 12:23:58 +0800
commit40fc27154fe754181934dc7ee31375e6bdfb33fc (patch)
tree897ad98d759bc308ef66561181ba88b85f2ccd47 /src/lua/libraries/luax/luax.h
parent1480c9445100075c9e1a894eb07c0ef727b509a1 (diff)
*merge from minimal
Diffstat (limited to 'src/lua/libraries/luax/luax.h')
-rw-r--r--src/lua/libraries/luax/luax.h88
1 files changed, 63 insertions, 25 deletions
diff --git a/src/lua/libraries/luax/luax.h b/src/lua/libraries/luax/luax.h
index 56023b3..fd10737 100644
--- a/src/lua/libraries/luax/luax.h
+++ b/src/lua/libraries/luax/luax.h
@@ -39,13 +39,18 @@
#define luax_dostring luaL_dostring
#define luax_pcall lua_pcall
#define luax_setglobal lua_setglobal
+#define luax_setglobali(L, i, name)\
+lua_pushvalue(L, i);\
+lua_setglobal(L, name);
#define luax_pop lua_pop
#define luax_newtable lua_newtable
#define luax_getglobal lua_getglobal
+
+#define luax_clear(L) lua_settop(L, 0)
/**
*
*/
-#define luax_setglobal_string(L, n, v) (lua_pushstring(L, v), lua_setglobal(L, n))
+#define luax_setglobalstring(L, n, v) (lua_pushstring(L, v), lua_setglobal(L, n))
/**
* Get number of args
@@ -82,6 +87,7 @@ inline bool luax_checkbool(lua_State *L, int numArg)
/**
* Oprating tables.
*/
+/* get value and leaves it on top of stack */
#define luax_rawgetnumber(L, i, k) (lua_rawgeti(L,i, k), lua_tonumber(L, -1))
/**
@@ -104,6 +110,7 @@ inline bool luax_checkbool(lua_State *L, int numArg)
#define luax_pushinteger lua_pushinteger
#define luax_pushboolean lua_pushboolean
#define luax_pushlightuserdata lua_pushlightuserdata
+#define luax_pushnil lua_pushnil
//inline void luax_pushuserdata(lua_State* L, void* p)
//{
@@ -124,37 +131,38 @@ inline bool luax_checkbool(lua_State *L, int numArg)
#define luax_setfield_(T, L, k, v)\
do { lua_push##T(L, v); lua_setfield(L, -2, k); } while (0)
-#define luax_setfield_number(L, k, v) luax_setfield_(number, L, k, v)
-#define luax_setfield_string(L, k, v) luax_setfield_(string, L, k, v)
-#define luax_setfield_bool(L, k, v) luax_setfield_(boolean, L, k, v)
-#define luax_setfield_udata(L, k, v) luax_setfield_(lightuserdata, L, k, v)
-#define luax_setfield_cfunc(L, k, v) luax_setfield_(cfunction, L, k, v)
-#define luax_setfield_fstring(L, k, ...)\
+#define luax_setfieldnumber(L, k, v) luax_setfield_(number, L, k, v)
+#define luax_setfieldinteger(L, k, v) luax_setfield_(integer, L, k, v)
+#define luax_setfieldstring(L, k, v) luax_setfield_(string, L, k, v)
+#define luax_setfieldbool(L, k, v) luax_setfield_(boolean, L, k, v)
+#define luax_setfieldudata(L, k, v) luax_setfield_(lightuserdata, L, k, v)
+#define luax_setfieldcfunc(L, k, v) luax_setfield_(cfunction, L, k, v)
+#define luax_setfieldfstring(L, k, ...)\
do { lua_pushfstring(L, __VA_ARGS__); lua_setfield(L, -2, k); } while (0)
/**
* If nosuch field push a nil at the top of stack.
*/
#define luax_getfield(L, I, N) lua_getfield(L, I, N)
-inline float luax_getfield_number(lua_State* L, int I, const char* N)
+inline float luax_getfieldnumber(lua_State* L, int I, const char* N)
{
luax_getfield(L, I, N);
float n = luax_checknumber(L, -1);
return n;
}
-inline int luax_getfield_integer(lua_State* L, int I, const char* N)
+inline int luax_getfieldinteger(lua_State* L, int I, const char* N)
{
luax_getfield(L, I, N);
int bin = luax_checkinteger(L, -1);
return bin;
}
-inline const char* luax_getfield_string(lua_State* L, int I, const char* N)
+inline const char* luax_getfieldstring(lua_State* L, int I, const char* N)
{
luax_getfield(L, I, N);
const char* str = luax_checkstring(L, -1);
return str;
}
-inline char luax_getfield_bool(lua_State* L, int I, const char* N)
+inline char luax_getfieldbool(lua_State* L, int I, const char* N)
{
luax_getfield(L, I, N);
char bin = lua_toboolean(L, -1);
@@ -164,12 +172,12 @@ inline char luax_getfield_bool(lua_State* L, int I, const char* N)
/**
* Set raw
*/
-#define luax_setraw_(T, L, idx, i, v)\
+#define luax_setraw(T, L, idx, i, v)\
(lua_push##T(L, v), lua_rawseti(L, idx, i))
-#define luax_setraw_string(L, idx, i, v) luax_setraw_(string, L, idx, i, v)
-#define luax_setraw_number(L, idx, i, v) luax_setraw_(number, L, idx, i, v)
-#define luax_setraw_bool(L, idx, i, v) luax_setraw_(boolean, L, idx, i, v)
+#define luax_setrawstring(L, idx, i, v) luax_setraw(string, L, idx, i, v)
+#define luax_setrawnumber(L, idx, i, v) luax_setraw(number, L, idx, i, v)
+#define luax_setrawbool(L, idx, i, v) luax_setraw(boolean, L, idx, i, v)
/**
*
@@ -315,7 +323,7 @@ inline int luax_tableidxlen(lua_State* L, int i)
}
/**
-* Get table hash size
+* Get table hash size
inline int luax_tbalehashlen(lua_State* L, int i)
{
@@ -323,20 +331,20 @@ inline int luax_tbalehashlen(lua_State* L, int i)
*/
/**
-* Get table hash and index size
+* Get table hash and index size
inline int luax_tablelen(lua_State* L, int i)
{
}
*/
-/**
-* Set value i in stack a global value called v, and
-* don't pop it.
-*/
-#define luax_justglobal(L, i, v) (lua_pushvalue(L, i), lua_setglobal(L, v))
+/* create a global tbale and stay it on the top of stack */
+#define luax_globaltable(L, name)\
+lua_newtable(L);\
+lua_pushvalue(L, 1);\
+lua_setglobal(L, name);
-inline int luax_table_insert(lua_State * L, int tindex, int vindex, int pos)
+inline int luax_tableinsert(lua_State * L, int tindex, int vindex, int pos)
{
if (tindex < 0)
tindex = lua_gettop(L) + 1 + tindex;
@@ -363,7 +371,7 @@ inline int luax_table_insert(lua_State * L, int tindex, int vindex, int pos)
/**
* Add the package loader to the package.loaders table.
*/
-inline int luax_register_searcher(lua_State * L, lua_CFunction f, int pos)
+inline int luax_registersearcher(lua_State * L, lua_CFunction f, int pos)
{
lua_getglobal(L, "package");
@@ -376,11 +384,41 @@ inline int luax_register_searcher(lua_State * L, lua_CFunction f, int pos)
return luaL_error(L, "Can't register searcher: package.loaders table does not exist.");
lua_pushcfunction(L, f);
- luax_table_insert(L, -2, -1, pos);
+ luax_tableinsert(L, -2, -1, pos);
lua_pop(L, 3);
return 0;
}
+typedef struct luax_Str
+{
+ const char* name;
+ const char* value;
+} luax_Str;
+
+inline void luax_setfieldstrings(lua_State* L, const luax_Str* strs)
+{
+ for (int i = 0; strs[i].name != 0; ++i)
+ {
+ luax_setfieldstring(L, strs[i].name, strs[i].value);
+ }
+}
+
+typedef struct luax_Num
+{
+ const char* name;
+ float number;
+};
+
+inline void luax_setfieldnumbers(lua_State* L, const luax_Num* strs)
+{
+ for (int i = 0; strs[i].name != 0; ++i)
+ {
+ luax_setfieldnumber(L, strs[i].name, strs[i].number);
+ }
+}
+
+typedef luaL_Reg luax_Ref;
+
#endif // #if LUA_VERSION_NUM == 501
#endif // __LUAX_H \ No newline at end of file