[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strange assert in yieldk-resume
- From: Flyer31 Test <flyer31@...>
- Date: Thu, 2 Dec 2021 06:54:15 +0100
Ups, thank you ... this really is wrong in this code segment above -
must be str:sub of course.
(but this was not the problem ... strangly really my sys.sleep(0) only
works if I use it in this form sys.sleep(0) (WITH a parameter on
stack).
(I now considered as workaround, that before yielding I could push
just a zero integer on the stack and later remove it by lua-pop... but
I did not try this yet... it is not really very severe... just somehow
"a bit strange").
On Wed, Dec 1, 2021 at 7:51 PM Gé Weijers <ge@weijers.org> wrote:
>
> str.sub(i,j) should probably be str:sub(i, j) (colon instead of period)
>
>
> On Wed, Nov 24, 2021 at 12:12 PM Flyer31 Test <flyer31@googlemail.com> wrote:
>>
>> 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?
>
>
>
> --
> Gé