after I write this, I fall.
#include "lua.h"
#include "lauxlib.h"
LUA_API int luaopen_misc(lua_State *L)
{
lua_CFunction tosf;
lua_getglobal( L, "tostring" );
printf("get tostring from global, type(%s)\n", lua_typename(L,-1));
printf("get tostring from global, tostring(%s)\n", lua_tostring(L,-1));
tosf = lua_tocfunction( L, -1 );
printf("get tostring lua_CFunction pointer(%p)\n", tosf);
lua_pop(L,1);
lua_getglobal(L,"_G");
printf("_G tostring(%s)\n",lua_tostring(L,-1));
lua_getfield( L, -1, "tostring" );
printf("get tostring from global, type(%s)\n", lua_typename(L,-1));
printf("get tostring from global, tostring(%s)\n", lua_tostring(L,-1));
tosf = lua_tocfunction( L, -1 );
printf("get tostring lua_CFunction pointer(%p)\n", tosf);
lua_pop(L,1);
return 0;
}
---------------------------------
After run I got:
JIT: ON CMOV SSE2 SSE4.1 fold cse dce fwd dse narrow loop abc fuse
> require "misc"
get tostring from global, type(no value)
get tostring from global, tostring((null))
get tostring lua_CFunction pointer(00000000)
_G tostring((null))
get tostring from global, type(no value)
get tostring from global, tostring((null))
get tostring lua_CFunction pointer(00000000)
>