lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


There are only two things that stand out at me, both from the same function UCSimScript::Execute()
>
>   int UCSimScript::Execute(char * filename)
>   {
>       const struct luaL_reg oci [] = {
>           {"Call", &UCSimScript::L_Call},  //L_Call is
>   a static function , i includes this function as
>   below
>           {"CallAck", &UCSimScript::L_CallAck},
>           {"Alert", &UCSimScript::L_Alert},
>           {"Answer", &UCSimScript::L_Answer},
>           {"Release", &UCSimScript::L_Release},
>           {"ReleaseComplete",
>   &UCSimScript::L_ReleaseComplete},
>           {"Refid", &UCSimScript::L_Refid},
>           {NULL, NULL}  /* sentinel */
>       };

Is there any particular reason that this isn't static? Since it's not, you're recreating this on every call to Execute() which, while not a lot of time, is significant if it's being called 400 times per second.

It also leads into the second issue: Aren't you reloading your library on every call to Execute()? That means that Lua has to GC your old library and open your new library. Again, if this is happening 400 times per second, that could be pretty bad.

I may be misunderstanding your code, but I believe that you are using the same state for this. If that's the case, you should either load the library at construction instead of execution, or check to see if the library already exists before sticking it in.



As a side note, all of this can be done with the auxiliary library using luaL_check* or luaL_opt* and would make your code quite a bit cleaner, imho:

>       //first param (direction)
>       if ( lua_type(l, 1) == LUA_TNUMBER )
>       {
>           dir = lua_tointeger(l, 1);
>       }
>       else if ( lua_type(l, 1) != LUA_TNONE )
>           Lua_Error("Param 1 with wrong type or
>   value");

dir = luaL_checknumber(l, 1);

>
>       //2nd param (refid)
>       if ( lua_type(l, 2) == LUA_TSTRING )
>       {
>          snprintf(tmp,sizeof tmp,"%s" ,
>   lua_tostring(l, 2) );
>          refid=strtoull(tmp,NULL,16);
>       }
>       else if ( lua_type(l, 2) != LUA_TNONE )
>           Lua_Error("Param 2 with wrong type or
>   value");

refid = luaL_optstring(l, 2, NULL);


etc, etc...

Good luck,
-- Matthew P. Del Buono