> char name[512]; // yes I know, arbitrary constant > strncpy(name,iev->name,iev->len); > name[iev->len] = '\0'; > lua_pushstring(L,name); You can simply use lua_pushlstring(L,iev->name,iev->len).