[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Strange assert in yieldk-resume
- From: Flyer31 Test <flyer31@...>
- Date: Wed, 24 Nov 2021 21:12:15 +0100
I just try some test code, to compare my indexed string functions to
the standard Lua string functions.
For this I use the following Lua code (Lua V 5.4.3):
str= "This is some fairly long string to check the memory allocation stuff"
for i= 1, #str do
for j= 1, i do
tmp= str.sub( i, j)
sys.sleep( 0)
end
end
(My count-surveillance hook would close this down after 1000 lua
cycles, if I would skip this sys.sleep(0) ).
Like this it works nicely.
But usually I would like that the user could also invoke sys.sleep()
withOUT any parameter (so then 0 being the default parameter).
If I try this lua code instead (The difference here is the sys.sleep()
instead of sys.sleep(0)):
for i= 1, #str do
for j= 1, i do
tmp= str.sub( i, j)
sys.sleep()
end
end
Then the first invoke of sys.sleep() will work fine, but then I return
yieldk in my sys_sleep function, and when lua_resume is invoked, the
lua_resume will "crash" with a strange assertion (source file ldo.c,
line 787):
api_checknelems(L, (L->status == LUA_OK) ? nargs + 1 : nargs);
Somehow lua_resume does not allow me to use this yieldk-resume cycle,
if my sys.sleep has no stack parameters (lua_gettop(L) for sys.sleep()
is 0, but nargs is 1 in this lua_resume assert invocation, so somehow
here lua_gettop(L)>= 1 required, as I understand it?).
Is there some special reason for this condition of a stack parameter?
(my sys.sleep function is very easy, and my yield-resume programming
should be free of errors, I am quite sure, it is running elsewise very
perfectly... except this strange problem:
float fsec;
static int lua_sleep( lua_State* L){
fsec= lua_isnone(L, 1) ? 0 : luaL_checknumber( L, 1);
return lua_yieldk( L, 0, 0, y_sys_sleep);
}
static int y_lua_sleep( lua_State* L, int /* status*/, lua_KContext ptr){
if( myUptimeFunc() > fsec)
return 0;
return y_lua_sleep( L, 0, ptr);
}
Has anybody some hint, where I my code might have some problem here
with lua_resume, if I invoke my lua_sleep with no stack parameter?