<jupyter_start><jupyter_text>做一个动态链接库```shcd ../skynet-master  编译cc -g -O2 -Wall -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -I3rd/lua  -o libskynet.so skynet-src/skynet_main.c skynet-src/skynet_handle.c skynet-src/skynet_module.c skynet-src/skynet_mq.c skynet-src/skynet_server.c skynet-src/skynet_start.c skynet-src/skynet_timer.c skynet-src/skynet_error.c skynet-src/skynet_harbor.c skynet-src/skynet_env.c skynet-src/skynet_monitor.c skynet-src/skynet_socket.c skynet-src/socket_server.c skynet-src/malloc_hook.c skynet-src/skynet_daemon.c skynet-src/skynet_log.c 3rd/lua/liblua.a -Iskynet-src -I3rd/jemalloc/include/jemalloc   -lpthread -lm -ldl -DNOUSE_JEMALLOC```<jupyter_code>from cffi import FFI
ffi = FFI()
ffi.cdef("""

const char * skynet_getenv(const char *key);
void skynet_setenv(const char *key, const char *value);

void skynet_env_init();
""", override=True)


lib = ffi.dlopen('../skynet-master/libskynet.so')

lib.skynet_env_init()
# 定义变量
k = ffi.new("char[]", b"v1")
v = ffi.new("char[]", b"100")

k = b"host"
v = b"localhost"
lib.skynet_setenv(k, v)
ffi.string(lib.skynet_getenv(k))
# 赋值
for i in range(10):
    k = b"V%d"%i
    v = b"%d"%i
    lib.skynet_setenv(k, v)
    

# 获得值
for i in range(10):
    k = b"V%d"%i
    print(ffi.string(lib.skynet_getenv(k)))<jupyter_output>b'0'
b'1'
b'2'
b'3'
b'4'
b'5'
b'6'
b'7'
b'8'
b'9'<jupyter_text>测试 setenv 时,  key已经存在```C/** 向lua虚拟机中 */void skynet_setenv(const char *key, const char *value) {	SPIN_LOCK(E)		lua_State *L = E->L;	lua_getglobal(L, key); // 将 key对应的值压入栈顶	assert(lua_isnil(L, -1)); // key 对应的值应该为 nil. 如果不为 nil?	lua_pop(L,1);	lua_pushstring(L,value);	lua_setglobal(L,key);	SPIN_UNLOCK(E)}```<jupyter_code>k = b"key_t2"
v = b"value of t2"
lib.skynet_setenv(k, v)<jupyter_output><empty_output><jupyter_text>使用原有 k 继续<jupyter_code>v = b"value 2 of t2"
lib.skynet_setenv(k, v)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16932059447983014, 'fraction_numerical': 0.014861995753715499, 'mean_word_length': 5.100323624595469, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '177434', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 971, 'n_tokens_neox': 979, 'n_words': 146, 'path': 'notebook/test_skynet_env.ipynb', 'repo_name': 'cf2012/skynet-annotated', 'size': '1884'}