luaL_loadbuffer
loads the script but does not run it. onData
will only be defined when the script is run.
Try calling luaL_dostring
instead of luaL_loadbuffer
.
Or add lua_pcall(CO,0,0,0)
before lua_getglobal
.
Moreover, you need lua_resume(CO,NULL,1)
to pass data
to onData
.