void context_lua_t::lua_load_env(lua_State *L, char* env[]) { lua_checkstack(L, 3); luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); lua_getfield(L, -1, LUA_LOADLIBNAME); /* _LOADED[name] */ if (lua_istable(L, -1)) { char** envp = env; lua_getfield(L, -1, "path"); size_t path_len; const char* lua_path = lua_tolstring(L, -1, &path_len); if (lua_path != NULL && path_len > 0) { char* lua_path_env = (char*)nl_malloc(path_len + 10); strcpy(lua_path_env, "LUA_PATH="); strcpy(lua_path_env + 9, lua_path); *envp++ = lua_path_env; } lua_pop(L, 1); lua_getfield(L, -1, "cpath"); size_t cpath_len; const char* lua_cpath = lua_tolstring(L, -1, &cpath_len); if (lua_cpath != NULL && cpath_len > 0) { char* lua_cpath_env = (char*)nl_malloc(cpath_len + 11); strcpy(lua_cpath_env, "LUA_CPATH="); strcpy(lua_cpath_env + 10, lua_cpath); *envp++ = lua_cpath_env; } lua_pop(L, 3); return; } lua_pop(L, 2); return; }
extern void* nl_memdup(const void* src, uint32_t len) { if (src) { if (len != 0) { void* temp = nl_malloc(len); if (temp) { return memcpy(temp, src, len); } } else { return nl_malloc(1); } } return NULL; }
void uv_udp_handle_t::on_read(uv_udp_t* handle, ssize_t nread, uv_buf_t buf, struct sockaddr* addr, unsigned flags) { /* udp max datagram read pack size: SHARED_READ_BUFFER_SIZE(64 * 1024) */ if (nread == 0) { return; } uv_udp_handle_t* udp_handle = (uv_udp_handle_t*)(handle->data); if (nread == -1) { singleton_ref(node_lua_t).context_send(udp_handle->m_source, 0, udp_handle->m_lua_ref, RESPONSE_UDP_READ, singleton_ref(network_t).last_error()); return; } buffer_t buffer = buffer_new(nread, buf.base, nread); char* host = (char*)nl_malloc(64); uint16_t port = 0; bool ipv6 = false; *host = '\0'; sockaddr_host(addr, host, 64, &ipv6, &port); message_array_t* array = message_array_create(4); array->m_array[0] = message_t(0, udp_handle->m_lua_ref, RESPONSE_UDP_READ, buffer); array->m_array[1] = message_t(0, udp_handle->m_lua_ref, RESPONSE_UDP_READ, host); array->m_array[2] = message_t(0, udp_handle->m_lua_ref, RESPONSE_UDP_READ, (int64_t)port); array->m_array[3] = message_t(0, udp_handle->m_lua_ref, RESPONSE_UDP_READ, ipv6); singleton_ref(node_lua_t).context_send_array_release(udp_handle->m_source, 0, udp_handle->m_lua_ref, RESPONSE_UDP_READ, array); }