diff options
Diffstat (limited to 'src/lua.c')
| -rw-r--r-- | src/lua.c | 82 |
1 files changed, 27 insertions, 55 deletions
@@ -5,6 +5,7 @@ #include <string.h>
#include "types/str.h"
#include <stdint.h>
+#include "util.h"
#include "types/parray.h"
static int malloc_count = 0;
@@ -13,6 +14,32 @@ int luaI_nothing(lua_State* L){ return 0;
}
+int luaI_lowercase_index(lua_State* L){
+ if(lua_type(L, 2) == LUA_TSTRING){
+ str* s = str_init(lua_tostring(L, 2));
+ str_lowercase(s);
+ lua_pushlstring(L, s->c, s->len);
+ str_free(s);
+ }
+ lua_rawget(L, 1);
+
+ return 1;
+}
+
+int luaI_lowercase_newindex(lua_State* L){
+ if(lua_type(L, 2) == LUA_TSTRING){
+ str* s = str_init(lua_tostring(L, 2));
+ str_lowercase(s);
+ lua_pushlstring(L, s->c, s->len);
+ str_free(s);
+ lua_pushvalue(L, 3);
+ }
+
+ lua_rawset(L, 1);
+ return 0;
+}
+
+
int luaI_iserror(lua_State* L){
if(lua_gettop(L) < 3) return 0;
return lua_type(L, -3) == LUA_TNIL &&
@@ -322,61 +349,6 @@ void luaI_deepcopy(lua_State* src, lua_State* dest, enum deep_copy_flags flags){ lua_settop(src, old_top);
}
-void luaI_deepcopy2(lua_State* src, lua_State* dest){
- switch(lua_type(src, -1)){
- case LUA_TNUMBER:
- lua_pushinteger(dest, lua_tointeger(src, -1));
- break;
-
- case LUA_TSTRING:;
- size_t size = 0;
- const char* str = lua_tolstring(src, -1, &size);
- lua_pushlstring(dest, str, size);
- break;
-
- case LUA_TTABLE:;
- const void* p = lua_topointer(src, -1);
- char* p_string = calloc(80, sizeof * p_string);
- sprintf(p_string, "%p", p);
-
- //lua_getfield(dest, LUA_REGISTRYINDEX, p_string);
- lua_pushstring(dest, p_string);
- lua_gettable(dest, LUA_REGISTRYINDEX);
- if(!lua_isnil(dest, -1)){
- break;
- }
-
- lua_pop(dest, 1);
- lua_pushstring(dest, p_string);
- lua_newtable(dest);
- //lua_setfield(dest, LUA_REGISTRYINDEX, p_string);
- //lua_getfield(dest, LUA_REGISTRYINDEX, p_string);
- lua_settable(dest, LUA_REGISTRYINDEX);
-
- lua_pushstring(dest, p_string);
- lua_gettable(dest, LUA_REGISTRYINDEX);
-
- free(p_string);
-
- int src_top = lua_gettop(src);
- int dest_top = lua_gettop(dest);
-
- lua_pushnil(src);
- for(;lua_next(src, src_top) != 0;){
- luaI_deepcopy2(src, dest);
- lua_pop(src, 1);
- luaI_deepcopy2(src, dest);
-
- lua_settable(dest, dest_top);
- }
- break;
-
- default:
- lua_pushinteger(dest, 4);
- break;
- }
-}
-
int env_table(lua_State* L, int provide_table){
if(provide_table == 0){
lua_newtable(L);
|
