Re: Getting number of messages in MessageBox
On Tuesday, 6 August 2013 at 06:15:20 UTC, Marek Janukowicz wrote: Ali Çehreli wrote: On 08/05/2013 04:18 PM, Marek Janukowicz wrote: I'm using std.concurrency message passing and I'd like to check which thread might be a bottleneck. The easiest would be check number of messages piled up for each of them, but I could not find a way to do that. Is it possible? Every detail about MessageBox seems to be hidden... Would setMaxMailboxSize() be helpful? void setMaxMailboxSize(Tid tid, size_t messages, bool function(Tid) onCrowdingDoThis); You can set a limit (perhaps that is lower than normal operation) and report whenever a particular Tid's MessageBox gets full. Well, while this could help a little, it's not really what I'm looking for. I'd like to dump message counts for various threads periodically and see how it fluctuates over time. With the solution you propose I could only check how often a certain limit is hit. Why not go for the trivial solution - just increase/decrease a counter for each push/pop message?
Re: Getting number of messages in MessageBox
On Tuesday, 6 August 2013 at 07:47:10 UTC, Marek Janukowicz wrote: dennis luehring wrote: the question is do the published counter then needs locking - and make it slow for all - just for beeing getable? Good point - but I believe the code operating on the counter is synchronized already, so synchronized getter would not really slow things down. I agree that this is much needed feature. In python for example, the threaded Queue class has qsize() method that returns the APPROX size of the queue. Without it my life would be much harder-I use it frequently.
Re: Started to work on a Lua wrapper. Please provide feedback guidance
On Monday, 5 August 2013 at 19:14:25 UTC, Jesse Phillips wrote: On Saturday, 3 August 2013 at 22:17:32 UTC, Gabi wrote: I need a Lua 5.2.2 wrapper, So I started working on one.. I am new to D so probably there is a lot of room for improvements.. Any feedback is welcome.. You'll probably like the LuaD wrapper https://github.com/JakobOvrum/LuaD It uses 5.1, but may be usable with 5.2 or simple to get the basics working. There is currently a bug open: https://github.com/JakobOvrum/LuaD/issues/19 So if you get it working for yourself, contributing back would be good. Right! I like this approach. That what I tried to achieve in my Lua class above. Will be happy to contribute if I can
Variadic functions: How to pass another variadic function the variadic args?
void F1(...) { } void F2(...) { //HOW TO pass F1(..) the args we were called with ? }
Re: Variadic functions: How to pass another variadic function the variadic args?
On Saturday, 3 August 2013 at 14:58:49 UTC, bearophile wrote: Gabi: //HOW TO pass F1(..) the args we were called with ? import std.stdio; void f1(Args...)(Args args) { foreach (arg; args) arg.writeln; } void f2(Args...)(Args args) { f1(args); } void main() { f2(10, hello, 1.5); } Bye, bearophile Thanks but how do I do this for variadic functions (using _arguments and friends) ? Not variadic templates.. More specifically I want to know at runtime the type of each parameter
Re: Variadic functions: How to pass another variadic function the variadic args?
On Saturday, 3 August 2013 at 18:48:17 UTC, monarch_dodra wrote: On Saturday, 3 August 2013 at 16:57:41 UTC, Gabi wrote: On Saturday, 3 August 2013 at 14:58:49 UTC, bearophile wrote: Gabi: //HOW TO pass F1(..) the args we were called with ? import std.stdio; void f1(Args...)(Args args) { foreach (arg; args) arg.writeln; } void f2(Args...)(Args args) { f1(args); } void main() { f2(10, hello, 1.5); } Bye, bearophile Thanks but how do I do this for variadic functions (using _arguments and friends) ? Not variadic templates.. More specifically I want to know at runtime the type of each parameter I don't know how to do runtime variadics in D, and quite frankly, I don't want to know: They are an abomination, and I don't want to be anywhere near these things. My guess though, is that it's the same syntax as in C? Use a straight up elispis: void foo(...). Note that you *can't* extract the types from the vararg unless you *guess* them from an alternative source (for example, fmt in the printf function) Also, importing core.vararg should get you whatever you'd get in 'vararg.h'/stdarg.h. From there, I don't think D does anything specific that's not actually just C. Ok, I got an alternative solution. What do you think about the following ? void f(T:long) (T arg) { ... } void f(T:int) (T arg) { ... } void f(T:int) (T arg) { ... } void f(T:string) (T arg) { ... } void f1(ARGS...)(ARGS args) { foreach(arg; args) { f(arg); } }
Started to work on a Lua wrapper. Please provide feedback guidance
I need a Lua 5.2.2 wrapper, So I started working on one.. I am new to D so probably there is a lot of room for improvements.. Any feedback is welcome.. import std.stdio:writeln, writefln; import std.exception:enforce; import std.conv; import std.string; alias void lua_State; alias long lua_Integer; alias double lua_Number; enum LUA_OK = 0; enum LUA_MULTRET = -1; extern (C) { lua_State *luaL_newstate (); void lua_close (lua_State *L); void luaL_openlibs (lua_State *L); int lua_gettop (lua_State *L); void lua_settop (lua_State *L, int index); int luaL_loadstring (lua_State *L, const char *s); int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, int ctx, void*); void lua_setglobal (lua_State *L, const char *name); void lua_getglobal (lua_State *L, const char *name); void lua_getfield (lua_State *L, int index, const char *k); lua_Number lua_tonumberx (lua_State *L, int index, int *isnum); lua_Integer lua_tointegerx (lua_State *L, int index, int *isnum); const char *lua_tolstring (lua_State *L, int index, size_t *len); const char *lua_pushstring (lua_State *L, const char *s); void lua_pushinteger (lua_State *L, lua_Integer n); void lua_pushnumber (lua_State *L, lua_Number n); } class LuaException:Exception { this (string msg) { super(msg); } } class Lua { private: lua_State* _luaState; void _pushArg(long arg) { lua_pushinteger(_luaState, arg); } void _pushArg(int arg) { lua_pushinteger(_luaState, to!long(arg)); } void _pushArg(double arg) { lua_pushnumber(_luaState, arg); } void _pushArg(float arg) { lua_pushnumber(_luaState, to!double(arg)); } void _pushArg(string arg) { lua_pushstring(_luaState, arg.ptr); } void _pushArg(const char* arg) { lua_pushstring(_luaState, arg); } void _runFun(ARGS...)(string packageName, string funName, ARGS args) { if(packageName.length == 0 || packageName == .) { lua_getglobal(_luaState, funName.ptr); } else { lua_getglobal(_luaState, packageName.ptr); lua_getfield(_luaState, -1, funName.ptr); } //Push arguments foreach(arg; args) { _pushArg(arg); } int rv = lua_pcallk(_luaState, cast(int)args.length, 1, 0, 0, null ); enforce(rv == LUA_OK, new LuaException(runFun:lua_pcallk failed)); } public: this() { _luaState = luaL_newstate(); enforce(_luaState != null, new LuaException(luaL_newstate() failed)); luaL_openlibs(_luaState); } ~this() { close(); } void close() { if(_luaState != null) lua_close(_luaState); } @property lua_State* luaState() { return _luaState; } /* * Load function * Throw LuaException on error */ void loadFun(string funBody) { int rv = luaL_loadstring(_luaState, funBody.ptr); enforce(rv == LUA_OK, new LuaException(loadFun:luaL_loadstring failed)); rv = lua_pcallk(_luaState, 0, LUA_MULTRET, 0, 0, null); enforce(rv == LUA_OK, new LuaException(loadFun:lua_pcallk failed)); } /* * Load function and give it a name. * funBody should be anonymous function like function(x,y)..end * Throw LuaException on error */ void loadFun(string funName, string funBody) { loadFun(funName ~ = ~funBody); } /* * Execute the given function and return it rv * packageName can be empty or . for global scope function * Throw LuaException on error */ T runFun(T:double, ARGS...)(string packageName, string funName, ARGS args) { int top = lua_gettop(_luaState); _runFun(packageName, funName, args); scope(exit) lua_settop(_luaState, top); return lua_tonumberx(_luaState, -1, null); } T runFun(T:long, ARGS...)(string packageName, string funName, ARGS args) { int top = lua_gettop(_luaState); _runFun(packageName, funName, args); scope(exit) lua_settop(_luaState, top); return lua_tointegerx(_luaState, -1, null); } T runFun(T:string, ARGS...)(string packageName, string funName, ARGS args) { int top = lua_gettop(_luaState); scope(exit) lua_settop(_luaState, top); _runFun(packageName, funName, args); const char* rv = lua_tolstring(_luaState, -1, null); return to!string(rv); } T runFun(T:const char*, ARGS...)(string packageName, string funName, ARGS args) { int top = lua_gettop(_luaState); scope(exit) lua_settop(_luaState, top); _runFun(packageName, funName, args); return lua_tolstring(_luaState, -1, null); } } unittest { string fn1 =
How to define struct with function pointer member ?
I tried: struct X { .. function double(Individual) someFun; .. } But get: Error: Declaration expected, not 'function' Thanks, Gabi
Re: How to define struct with function pointer member ?
On Sunday, 28 July 2013 at 22:04:57 UTC, Gabi wrote: I tried: struct X { .. function double(Individual) someFun; .. } But get: Error: Declaration expected, not 'function' Thanks, Gabi Sorry I found the answer. Should have declared double function(...) someFun;
Re: How to define struct with function pointer member ?
On Sunday, 28 July 2013 at 22:13:13 UTC, H. S. Teoh wrote: On Mon, Jul 29, 2013 at 12:04:55AM +0200, Gabi wrote: I tried: struct X { .. function double(Individual) someFun; [...] The correct syntax is: double function(Individual) someFun; T Yes thanks. Beginner's mistake :)
Re: How to get warnings about unused imports ?
On Wednesday, 3 July 2013 at 06:12:46 UTC, Namespace wrote: On Tuesday, 2 July 2013 at 21:49:37 UTC, Gabi wrote: Hi, How to find unused imports ? It seems the compiler doesn't do it, but is there any other tool for that? This seems like small issue, but those unused imports pile up pretty quickly Regards, Gabi I'm working on something like that for a few days. It is still not completely finished, but it works so far. But currently only for named imports. Everything else was far too much work for me. https://github.com/Dgame/SimpleDAT This is great. Maybe point me to the right direction how to implement finding unnamed imports too ? It could be great exercise for me to learn D :)
How to get warnings about unused imports ?
Hi, How to find unused imports ? It seems the compiler doesn't do it, but is there any other tool for that? This seems like small issue, but those unused imports pile up pretty quickly Regards, Gabi