| 1944 | } |
| 1945 | |
| 1946 | static int lua_real_execute_contract_api(lua_State *L |
| 1947 | , const char *contract_name, const char *api_name, const char *arg1 |
| 1948 | ) |
| 1949 | { |
| 1950 | /* |
| 1951 | if (lua_gettop(L) < 2) |
| 1952 | return 0; |
| 1953 | const char *contract_name = luaL_checkstring(L, 1); |
| 1954 | const char *api_name = luaL_checkstring(L, 2); |
| 1955 | const char *arg1 = lua_gettop(L)>2 && lua_isstring(L, 3) ? luaL_checkstring(L, 3) : nullptr; |
| 1956 | */ |
| 1957 | std::string arg1_str = arg1 ? std::string(arg1) : ""; // 这里单独保存一份是因为arg1,可能栈上数据哪里被pop了 |
| 1958 | |
| 1959 | // FIXME |
| 1960 | if (!(glua::util::starts_with(contract_name, STREAM_CONTRACT_PREFIX) |
| 1961 | || glua::util::starts_with(contract_name, ADDRESS_CONTRACT_PREFIX)) |
| 1962 | && !global_glua_chain_api->check_contract_exist(L, contract_name)) |
| 1963 | { |
| 1964 | global_glua_chain_api->throw_exception(L, THINKYOUNG_API_SIMPLE_ERROR, "can't find this contract"); |
| 1965 | lua_pushinteger(L, LUA_ERRRUN); |
| 1966 | return 1; |
| 1967 | } |
| 1968 | bool is_address = glua::util::starts_with(contract_name, ADDRESS_CONTRACT_PREFIX); |
| 1969 | char address[CONTRACT_ID_MAX_LENGTH + 1] = "\0"; |
| 1970 | size_t address_size = 0; |
| 1971 | std::string wrapper_contract_name_str = thinkyoung::lua::lib::wrap_contract_name(contract_name); |
| 1972 | std::string unwrapper_name = thinkyoung::lua::lib::unwrap_any_contract_name(contract_name); |
| 1973 | if (!is_address) |
| 1974 | global_glua_chain_api->get_contract_address_by_name(L, unwrapper_name.c_str(), address, &address_size); |
| 1975 | else |
| 1976 | { |
| 1977 | strncpy(address, unwrapper_name.c_str(), CONTRACT_ID_MAX_LENGTH); |
| 1978 | address_size = unwrapper_name.length(); |
| 1979 | address[address_size] = '\0'; |
| 1980 | } |
| 1981 | // std::stringstream codess; |
| 1982 | // codess << "import_contract '" << contract_name << "'"; |
| 1983 | // luaL_dostring(L, codess.str().c_str()); |
| 1984 | auto saved_out = L->out; |
| 1985 | auto saved_err = L->err; |
| 1986 | L->out = nullptr; |
| 1987 | L->err = nullptr; |
| 1988 | lua_pushstring(L, contract_name); |
| 1989 | |
| 1990 | std::string api_name_str(api_name); |
| 1991 | |
| 1992 | luaL_import_contract_module(L); // FIXME: searcher_Lua添加了时, 这里好像内存越界,改动了api_name, pushnexttemplate这个函数好像有问题 |
| 1993 | |
| 1994 | lua_settop(L, 1); /* _LOADED table will be at index 2 */ |
| 1995 | |
| 1996 | lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 1997 | lua_getfield(L, 2, wrapper_contract_name_str.c_str()); /* _LOADED[name] */ |
| 1998 | |
| 1999 | L->out = saved_out; |
| 2000 | L->err = saved_err; |
| 2001 | |
| 2002 | if (!lua_toboolean(L, -1)) /* is it there? */ |
| 2003 | { |
no test coverage detected