Re: Error flabergastation
On 08/02/2016 06:56 PM, Mark J Twain wrote: winmain.d(40): Error: found 'while' when expecting ';' following statement winmain.d(40): Error: unexpected ( in declarator winmain.d(40): Error: basic type expected, not & winmain.d(40): Error: found '&' when expecting ')' winmain.d(40): Error: found 'msg' when expecting ')' winmain.d(40): Error: missing { ... } for function literal winmain.d(40): Error: found ')' when expecting ';' following statement winmain.d(40): Error: found ')' instead of statement winmain.d(46): Error: unexpected ( in declarator winmain.d(46): Error: basic type expected, not 10 winmain.d(46): Error: found '10' when expecting ')' winmain.d(46): Error: no identifier for declarator Sleep(_error_) winmain.d(46): Error: semicolon expected following function declaration winmain.d(46): Error: declaration expected, not ')' winmain.d(47): Error: unrecognized declaration all that for a 10 line app that has a missing semicolon after a function call! Sleep has nothing to do with it! Walter explains how dmd behaves upon errors here: https://www.youtube.com/watch?v=l_96Crl998E=8=PL3jwVPmk_PRyTWWtTAZyvmjDF4pm6EX6z=2761 Ali
Re: DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?
On Tuesday, 2 August 2016 at 16:31:30 UTC, Sai wrote: I see that there are ports of go compiler on ev3dev (ARM, debian based) for controlling the EV3 lego mindstorm robot. (http://www.ev3dev.org/docs/libraries/) Is there a port of a D compiler for ARM? How about libraries? I need a basic file IO and console IO for controlling the robot. Thanks in advance Sai The reference compiler DMD doesn't support ARM, but LDC does and since recently it's quite up-to-date with the latest D-frontend release. Have a look at the LDC wiki entry and the linked entries: https://wiki.dlang.org/LDC#ARM
Re: DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?
On 03/08/2016 4:31 AM, Sai wrote: I see that there are ports of go compiler on ev3dev (ARM, debian based) for controlling the EV3 lego mindstorm robot. (http://www.ev3dev.org/docs/libraries/) Is there a port of a D compiler for ARM? How about libraries? I need a basic file IO and console IO for controlling the robot. Thanks in advance Sai GDC may work, but you will need to handle all the interfacing code to the platform. Also don't expect e.g. threading to work I suspect.
Passing refs with delegates
It's nice to be able to pass delegates and functions as callbacks. A nice feature is something like R foo(R,Args...)(R function(Args) callback, Args args) { return callback(args); } There are two problems with this. One is that type deduction doesn't work. I have to explicitly specify the types of args. This creates a lot of verbosity. Second, I can't pass ref parameters. The usefulness of this method is that it sort of lets you pass data in and out of the callback, all defined by the user calling foo. Sometimes you want to pass in references to store data and other times you don't. Is this a bug in D's type checking system or unfinished work or simply nonsense? right now I pass in pointers, but that doesn't work to well for some types, and is messy.
Error flabergastation
winmain.d(40): Error: found 'while' when expecting ';' following statement winmain.d(40): Error: unexpected ( in declarator winmain.d(40): Error: basic type expected, not & winmain.d(40): Error: found '&' when expecting ')' winmain.d(40): Error: found 'msg' when expecting ')' winmain.d(40): Error: missing { ... } for function literal winmain.d(40): Error: found ')' when expecting ';' following statement winmain.d(40): Error: found ')' instead of statement winmain.d(46): Error: unexpected ( in declarator winmain.d(46): Error: basic type expected, not 10 winmain.d(46): Error: found '10' when expecting ')' winmain.d(46): Error: no identifier for declarator Sleep(_error_) winmain.d(46): Error: semicolon expected following function declaration winmain.d(46): Error: declaration expected, not ')' winmain.d(47): Error: unrecognized declaration all that for a 10 line app that has a missing semicolon after a function call! Sleep has nothing to do with it!
Re: [Derelict-Lua] compiler error when lua_register is called
On Tuesday, 2 August 2016 at 16:44:39 UTC, Mike Parker wrote: On Tuesday, 2 August 2016 at 14:23:55 UTC, Jack wrote: [...] lua_register takes function pointers that in the form of lua_CFunction, an alias you can find declared in derelict.lua.types [1]. As you'll see there, it is declared to be both extern(C) and nothrow. Make your button function nothrow an you should be good to go. [1] https://github.com/DerelictOrg/DerelictLua/blob/master/source/derelict/lua/types.d#L103 Thank you!
opAssign is not callable because it is annotated with @disable with SysTime(Possible bug?)
Hello, I am currently trying to improve the TOML library of: https://github.com/iccodegr/toml.d I get a really weird error: Error: function main.TOMLValue.opAssign is not callable because it is annotated with @disable I have tested this with dmd 2.071.1 and 2.068.0. Here is the code to reproduce it: import std.datetime: SysTime, DateTime; import std.stdio; import std.conv; import std.exception; enum TOMLType { String, Integer, Float, Boolean, DateTime, Array, Group } // Changing this to DateTime makes it compile alias TOMLDateTimeType = SysTime; class TOMLException: Exception { this(string msg, string file="parser", size_t line=111) { super(msg, file, line); } } alias enforceTOML = enforceEx!(TOMLException); struct TOMLValue { union Store { string stringv; long intv; float floatv; bool boolv; TOMLDateTimeType datetimev; TOMLValue[] arrayv; TOMLValue[string] keygroups; } private { Store _store; TOMLType _type; } // Does not work with this either //private void assign(T)(T val, string key) { //static if ( is(T: TOMLValue) ) //_store.keygroups[key] = val; //else //_store.keygroups[key] = TOMLValue(val); //} TOMLValue opIndexAssign(TOMLValue v, string key) { enforceTOML(_type==TOMLType.Group); _store.keygroups[key] = v; return v; } } void main() { TOMLType a = TOMLType.String; writeln(a.to!string); } It doesn't really make any sense to me. Could anyone explain to me what's going on? Thank you for your time
Re: Cannot compare object.opEquals is not nogc
A hack is to create the gc code you in a function want to call, say does the "gc" opEquals. Then cast that function to a nogc version by first casting to a void*. This way you can call gc code from nogc code, by bypassing the compiler's ability to check. It will obviously break your code if you disable the gc completely and there are no easily ways to find the hacks(have to resort to marking and -vgs). @nogc void function() foo; void* bar = () { // Use GC }; alias A = @nogc void function(); foo = cast(A)bar; now foo, which points to the GC based bar, but is makred nogc and callable in nogc code. One can probably make a template GC2NoGC that does all this and to get completely off the GC, one just has to rework the anonymous functions(mark them nogc). So it is somewhat of a clean solution as it allows you to separate your gc dependencies in to well defined blocks that then can be addressed later when one truly wants to get off the GC.
Re: prolog and epilog code
On Tuesday, 2 August 2016 at 20:28:51 UTC, Rufus Smith wrote: On Tuesday, 2 August 2016 at 18:34:49 UTC, Steven Schveighoffer wrote: On 8/2/16 2:25 PM, Rufus Smith wrote: So, something funky is going on. Any ideas? phobos is not being resolved. I don't use visualD, so I'm not sure what the issue is, it's probably a compiler or linker ordering issue. -Steve Um, but it works as long as I a main function! So while it might be something weird with visualD, it's probably something more related to dmd(flag or something). Cause I am using phobo's... that is, unless it does not link in phobo's if there is no D main file(trying to be smart). If I link in phobos manually most of the errors go away, I'm left with" main.obj : error LNK2019: unresolved external symbol "int __cdecl rt_init(void)" (?rt_init@@YAHXZ) referenced in function main main.obj : error LNK2019: unresolved external symbol "void __cdecl Dmain(void)" (?Dmain@@YAXXZ) referenced in function main phobos64.lib(sections_win64_2317_4e2.obj) : error LNK2019: unresolved external symbol _deh_beg referenced in function _D2rt14sections_win6412SectionGroup8ehTablesMxFNdZAyS2rt15deh_win64_posix9FuncTable (const(@property immutable(rt.deh_win64_posix.FuncTable)[] function()) rt.sections_win64.SectionGroup.ehTables) phobos64.lib(sections_win64_2317_4e2.obj) : error LNK2019: unresolved external symbol _deh_end referenced in function _D2rt14sections_win6412SectionGroup8ehTablesMxFNdZAyS2rt15deh_win64_posix9FuncTable (const(@property immutable(rt.deh_win64_posix.FuncTable)[] function()) rt.sections_win64.SectionGroup.ehTables) This mainly seems that the d code is not being linked with the c code. But I guess this is all on VisualD's end since since it seems just to be the command line not getting the correct stuff, for some oddball reasons.
Re: function core.checkedint.muls cannot inline function
On Tuesday, 2 August 2016 at 18:32:42 UTC, Steven Schveighoffer wrote: On 8/2/16 2:09 PM, Etranger wrote: Hi, I'm trying to use the module core.checkedint, but I have a problem and I don't know if it is a bug or me. This simple program compiles well in debug mode with dmd, but give me an error when I compile in release mode: Error: function core.checkedint.muls cannot inline function import core.checkedint; void main() { ulong a = 1; ulong b =2; bool ovf; muls(a, b, ovf); } PS: it compiles with ldc2 Thanks for your help ! Bug. Please file: https://issues.dlang.org mulu also cannot be inlined. I'm curious how it passes unit tests, since druntime is compiled in release/inline mode. -Steve Thanks, I filed the bug https://issues.dlang.org/show_bug.cgi?id=16350
Re: prolog and epilog code
On Tuesday, 2 August 2016 at 18:34:49 UTC, Steven Schveighoffer wrote: On 8/2/16 2:25 PM, Rufus Smith wrote: So, something funky is going on. Any ideas? phobos is not being resolved. I don't use visualD, so I'm not sure what the issue is, it's probably a compiler or linker ordering issue. -Steve Um, but it works as long as I a main function! So while it might be something weird with visualD, it's probably something more related to dmd(flag or something). Cause I am using phobo's... that is, unless it does not link in phobo's if there is no D main file(trying to be smart).
Re: prolog and epilog code
On 8/2/16 2:25 PM, Rufus Smith wrote: So, something funky is going on. Any ideas? phobos is not being resolved. I don't use visualD, so I'm not sure what the issue is, it's probably a compiler or linker ordering issue. -Steve
Re: function core.checkedint.muls cannot inline function
On 8/2/16 2:09 PM, Etranger wrote: Hi, I'm trying to use the module core.checkedint, but I have a problem and I don't know if it is a bug or me. This simple program compiles well in debug mode with dmd, but give me an error when I compile in release mode: Error: function core.checkedint.muls cannot inline function import core.checkedint; void main() { ulong a = 1; ulong b =2; bool ovf; muls(a, b, ovf); } PS: it compiles with ldc2 Thanks for your help ! Bug. Please file: https://issues.dlang.org mulu also cannot be inlined. I'm curious how it passes unit tests, since druntime is compiled in release/inline mode. -Steve
Re: prolog and epilog code
On Tuesday, 2 August 2016 at 17:25:21 UTC, Steven Schveighoffer wrote: On 8/2/16 1:04 PM, Rufus Smith wrote: On Tuesday, 2 August 2016 at 16:30:08 UTC, Adam D. Ruppe wrote: On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote: How does one use C main? extern C? extern(C) int main() should do it It doesn't seem to be that easy! https://wiki.dlang.org/Runtime_internals This is just explaining how the runtime currently works, not how you should override it. It's really easy actually. Example: $ cat main.c #include extern int rt_init(); extern void d_func(); int main(int argc, char *argv[]) { printf("hello from C!\n"); rt_init(); printf("done initializing runtime\n"); d_func(); } $ cat dmain.d extern(C) void d_func() { import std.stdio; writeln("hello from D!"); } shared static this() { import std.stdio; writeln("doing some pre-run init!"); } $ gcc -c main.c $ dmd dmain.d main.o $ ./dmain hello from C! doing some pre-run init! done initializing runtime hello from D! -Steve When I do this in my project and try to link in the lib or obj created from the C project, I get "entry point must be defined" error. I tried to add both to the "command line". If I don't have a main function in D, I get all kinds of unresolved externals. Not sure why, but it seems to not import in the runtime when there is no main defined. Basically I created a side C++ project, copied your code in to the main.cpp. I then added the obj file to the linker command line path. Then I get the missing entry point error. It is very similar to yours, just using VisualD and windows. Seems like it would be easier just to create a wrapper process and use shared memory to transfer data between them ;/ For example, if I just create a new D project. Add a new cpp file and paste your C code in, paste the D code in the empty D file, and try to compile, I get: main.cpp main.obj : error LNK2019: unresolved external symbol "int __cdecl rt_init(void)" (?rt_init@@YAHXZ) referenced in function main main.obj : error LNK2019: unresolved external symbol "void __cdecl d_func(void)" (?d_func@@YAXXZ) referenced in function main CMain.obj : error LNK2001: unresolved external symbol _D14TypeInfo_Const6__vtblZ CMain.obj : error LNK2019: unresolved external symbol _d_throwc referenced in function _D3std9exception143__T12errnoEnforceTiVAyaa54_423a5c444c616e675c646d64325c77696e646f77735c62696e5c2e2e5c2e2e5c7372635c70686f626f735c7374645c737464696f2e64Vmi2543Z12errnoEnforceFNfiLAyaZi (@safe int std.exception.errnoEnforce!(int, "dmd2\windows\bin\..\..\src\phobos\std\stdio.d", 2543uL).errnoEnforce(int, lazy immutable(char)[])) CMain.obj : error LNK2001: unresolved external symbol _D12TypeInfo_Aya6__initZ CMain.obj : error LNK2019: unresolved external symbol _D3std3utf12isValidDcharFNaNbNiNfwZb referenced in function _D3std5stdio4File17LockingTextWriter10__T3putTwZ3putMFNbNiNfwZv CMain.obj : error LNK2019: unresolved external symbol _D3std9exception14ErrnoException6__ctorMFNeAyaAyamZC3std9exception14ErrnoException (@trusted std.exception.ErrnoException std.exception.ErrnoException.__ctor(immutable(char)[], immutable(char)[], ulong)) referenced in function _D3std9exception143__T12errnoEnforceTiVAyaa54_423a5c444c616e675c646d64325c77696e646f77735c62696e5c2e2e5c2e2e5c7372635c70686f626f735c7374645c737464696f2e64Vmi2543Z12errnoEnforceFNfiLAyaZi (@safe int std.exception.errnoEnforce!(int, "dmd2\windows\bin\..\..\src\phobos\std\stdio.d", 2543uL).errnoEnforce(int, lazy immutable(char)[])) CMain.obj : error LNK2019: unresolved external symbol _aApplycd1 referenced in function _D3std5stdio4File17LockingTextWriter12__T3putTAyaZ3putMFNfAyaZv (@safe void std.stdio.File.LockingTextWriter.put!(immutable(char)[]).put(immutable(char)[])) CMain.obj : error LNK2019: unresolved external symbol _D3std5stdio8__assertFiZv (void std.stdio.__assert(int)) referenced in function _D3std5stdio4File17LockingTextWriter10__T3putTwZ3putMFNbNiNfwZv CMain.obj : error LNK2019: unresolved external symbol _D3std5stdio4File17lockingTextWriterMFNfZS3std5stdio4File17LockingTextWriter (@safe std.stdio.File.LockingTextWriter std.stdio.File.lockingTextWriter()) referenced in function _D3std5stdio16__T7writelnTAyaZ7writelnFNfAyaZv (@safe void std.stdio.writeln!(immutable(char)[]).writeln(immutable(char)[])) CMain.obj : error LNK2001: unresolved external symbol _D3std5stdio12__ModuleInfoZ CMain.obj : error LNK2019: unresolved external symbol _D3std5stdio13trustedStdoutFNdNeZS3std5stdio4File (@property @trusted std.stdio.File std.stdio.trustedStdout()) referenced in function _D3std5stdio16__T7writelnTAyaZ7writelnFNfAyaZv (@safe void std.stdio.writeln!(immutable(char)[]).writeln(immutable(char)[])) CMain.obj : error LNK2019: unresolved external symbol _D3std3utf6toUTF8FNaNbNiNfNkJG4awZAa referenced in function _D3std5stdio4File17LockingTextWriter10__T3putTwZ3putMFNbNiNfwZv CMain.obj : error LNK2019: unresolved external
Re: Why Does Dscanner Warn About a Missing toHash if opEquals is Defined?
On Sunday, 31 July 2016 at 18:57:50 UTC, Jack Stouffer wrote: Next question: what's the fastest hashing implementation that will provide the least collisions? Is there a hash implementation that's perfered for AAs? I've heard that FNV-1a is a decent general-purpose option, and it's fairly straightforward. https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
function core.checkedint.muls cannot inline function
Hi, I'm trying to use the module core.checkedint, but I have a problem and I don't know if it is a bug or me. This simple program compiles well in debug mode with dmd, but give me an error when I compile in release mode: Error: function core.checkedint.muls cannot inline function import core.checkedint; void main() { ulong a = 1; ulong b =2; bool ovf; muls(a, b, ovf); } PS: it compiles with ldc2 Thanks for your help !
Re: prolog and epilog code
On 8/2/16 1:26 PM, Adam D. Ruppe wrote: On Tuesday, 2 August 2016 at 17:23:57 UTC, Adam D. Ruppe wrote: _d_run_main is extern(C), not just extern. Then your code should work. Also, you don't actually have to rt_init and rt_term if you do _d_run_main because it does it for you... I don't think this is supposed to be exposed. You should call the runtime in the expected way (i.e. rt_init, rt_term), because this may change in ways that would still compile but crash horrifically. -Steve
Re: prolog and epilog code
On Tuesday, 2 August 2016 at 17:23:57 UTC, Adam D. Ruppe wrote: _d_run_main is extern(C), not just extern. Then your code should work. Also, you don't actually have to rt_init and rt_term if you do _d_run_main because it does it for you...
Re: prolog and epilog code
On 8/2/16 1:04 PM, Rufus Smith wrote: On Tuesday, 2 August 2016 at 16:30:08 UTC, Adam D. Ruppe wrote: On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote: How does one use C main? extern C? extern(C) int main() should do it It doesn't seem to be that easy! https://wiki.dlang.org/Runtime_internals This is just explaining how the runtime currently works, not how you should override it. It's really easy actually. Example: $ cat main.c #include extern int rt_init(); extern void d_func(); int main(int argc, char *argv[]) { printf("hello from C!\n"); rt_init(); printf("done initializing runtime\n"); d_func(); } $ cat dmain.d extern(C) void d_func() { import std.stdio; writeln("hello from D!"); } shared static this() { import std.stdio; writeln("doing some pre-run init!"); } $ gcc -c main.c $ dmd dmain.d main.o $ ./dmain hello from C! doing some pre-run init! done initializing runtime hello from D! -Steve
Re: prolog and epilog code
On Tuesday, 2 August 2016 at 17:04:08 UTC, Rufus Smith wrote: It doesn't seem to be that easy! _d_run_main is extern(C), not just extern. Then your code should work. You can also simplify more: --- import std.stdio; import core.runtime; extern(C) int main() { rt_init(); writeln("Hello from D"); rt_term(); return 0; } ---
Re: prolog and epilog code
On Tuesday, 2 August 2016 at 16:30:08 UTC, Adam D. Ruppe wrote: On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote: How does one use C main? extern C? extern(C) int main() should do it It doesn't seem to be that easy! https://wiki.dlang.org/Runtime_internals If I do this then I get lots of missing imports(the D runtime). import std.stdio; import core.runtime; private alias extern(C) int function(char[][] args) MainFunc; extern int _d_run_main(int argc, char **argv, MainFunc mainFunc); extern(C) void main(int argc, char **argv) { rt_init(); _d_run_main(argc, argv, &_main); rt_term(); } extern(C) int _main(char[][] args) { return 0; } Or even using the code from the wiki, I get unresolved externals. Mainly the druntime like stuff(typeinfo, aa stuff, etc...).
Re: [Derelict-Lua] compiler error when lua_register is called
On Tuesday, 2 August 2016 at 14:23:55 UTC, Jack wrote: So basically I get the error "function button(lua_State* L) is not callable using argument types ()" whenever I try to lua_register a function. ``` lua_register(L,"button",button); ``` but whenever I use the function pointer I get the error "lua_register is not callable using argument types (lua_State*, char*,extern (C) int function(lua_State* L)" ``` lua_register(L,"button",); ``` Is this a bug, or am I doing something wrong here? lua_register takes function pointers that in the form of lua_CFunction, an alias you can find declared in derelict.lua.types [1]. As you'll see there, it is declared to be both extern(C) and nothrow. Make your button function nothrow an you should be good to go. [1] https://github.com/DerelictOrg/DerelictLua/blob/master/source/derelict/lua/types.d#L103
DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?
I see that there are ports of go compiler on ev3dev (ARM, debian based) for controlling the EV3 lego mindstorm robot. (http://www.ev3dev.org/docs/libraries/) Is there a port of a D compiler for ARM? How about libraries? I need a basic file IO and console IO for controlling the robot. Thanks in advance Sai
Re: prolog and epilog code
On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote: How does one use C main? extern C? extern(C) int main() should do it
Re: prolog and epilog code
On Tuesday, 2 August 2016 at 11:37:05 UTC, Steven Schveighoffer wrote: On 8/1/16 9:24 PM, Rufus Smith wrote: Can one add code that executes before the GC and any memory is normally allocated(even static) and after all of it was suppose to be released? Of course! You just have to modify druntime :) That doesn't sound like fun. Why doesn't D add a hook for program level static this(we have module level, need something more)? One thing you can do instead is compile without a D main function, and use C main, initialize the runtime manually. Then you can put your measurement code around the runtime initialization and termination. How does one use C main? extern C? Or do I have to actually write C code?
Re: Never-returning functions
On 8/2/16 11:34 AM, Enamex wrote: On Tuesday, 2 August 2016 at 15:18:31 UTC, Steven Schveighoffer wrote: What's wrong with assert(0) that you need to have a wrapper function for it? -Steve Nothing wrong exactly. I just wanted some descriptive terms to use in some places. Like "unreachable()" or "unimplemented()". Well, mixins could help: enum unreachable = "assert(0)"; ... // usage mixin(unreachable); Or comments: assert(0); // unreachable To be clear (and correct my original post now that I see it may have alluded to this), I want to say a function always 'throws', not necessarily asserts. This kind of flow control I don't think the compiler will infer. One thing you *could* do, is to define your function to return the appropriate return type, but of course it never will: T alwaysThrows(T)() { throw new Exception("blammo!"); return T.init; } int tryMe(bool f) { if(f) return 42; else return alwaysThrows!int; // or typeof(return) } -Steve
Re: Never-returning functions
On Tuesday, 2 August 2016 at 15:18:31 UTC, Steven Schveighoffer wrote: What's wrong with assert(0) that you need to have a wrapper function for it? -Steve Nothing wrong exactly. I just wanted some descriptive terms to use in some places. Like "unreachable()" or "unimplemented()". To be clear (and correct my original post now that I see it may have alluded to this), I want to say a function always 'throws', not necessarily asserts.
Re: Never-returning functions
On Tuesday, 2 August 2016 at 15:18:31 UTC, Steven Schveighoffer wrote: What's wrong with assert(0) that you need to have a wrapper function for it? while this is a legitimate question, the comipler's inability to infer "noreturn" still drives me mad. but if compiler will suddenly be able to infer that, it would lead to alot of "statement unreachable" warnings, and they are alot already...
Re: Never-returning functions
On 8/2/16 11:09 AM, Enamex wrote: I've tried to write an 'assert function' in D, one that doesn't trigger the 'function must return a value or assert' error. Basically something like: Never neverReturns() { assert(0); } or @noreturn auto neverReturns() { assert(0); } and int tryMe(bool f) { if(f) return 42; else neverReturns(); } Then have the call on line 2 in `tryMe` be accepted by the compiler. What's wrong with assert(0) that you need to have a wrapper function for it? -Steve
Never-returning functions
I've tried to write an 'assert function' in D, one that doesn't trigger the 'function must return a value or assert' error. Basically something like: Never neverReturns() { assert(0); } or @noreturn auto neverReturns() { assert(0); } and int tryMe(bool f) { if(f) return 42; else neverReturns(); } Then have the call on line 2 in `tryMe` be accepted by the compiler.
[Derelict-Lua] compiler error when lua_register is called
So basically I get the error "function button(lua_State* L) is not callable using argument types ()" whenever I try to lua_register a function. ``` lua_register(L,"button",button); ``` but whenever I use the function pointer I get the error "lua_register is not callable using argument types (lua_State*, char*,extern (C) int function(lua_State* L)" ``` lua_register(L,"button",); ``` Is this a bug, or am I doing something wrong here?
Re: prolog and epilog code
On 8/1/16 9:24 PM, Rufus Smith wrote: Can one add code that executes before the GC and any memory is normally allocated(even static) and after all of it was suppose to be released? Of course! You just have to modify druntime :) One thing you can do instead is compile without a D main function, and use C main, initialize the runtime manually. Then you can put your measurement code around the runtime initialization and termination. See here: http://dlang.org/phobos/core_runtime.html#.rt_init -Steve
Re: Replace (ie: substitute) a type in varadic args
On Tuesday, 2 August 2016 at 08:22:15 UTC, Saurabh Das wrote: On Tuesday, 2 August 2016 at 08:20:22 UTC, Saurabh Das wrote: On Tuesday, 2 August 2016 at 08:16:48 UTC, Sean Campbell wrote: [...] Thanks. Yes that is one approach. I figured out another approach that seems decent: auto targetFunctionProxy(Args...)(Args args) { import std.meta; return targetFunction!(ReplaceAll!(bool, ubyte, Args))(args); } PS: I'm unsure if this results in additional copying of arguments in the case where there are no bools in the arguments. Even if it does, the optimiser should take care of it. If it doesn't file a bug report.
Re: Replace (ie: substitute) a type in varadic args
On Tuesday, 2 August 2016 at 08:16:48 UTC, Sean Campbell wrote: On Tuesday, 2 August 2016 at 07:24:28 UTC, Saurabh Das wrote: [...] Just of the top of my head, using ugly string mixins, this: auto myConverterFunc(Args...)(Args args) { string genCode() { string code = "targetFunction("; foreach (i, Arg; Args) { static if (is(Arg == bool)) code ~= format("cast(ubyte)args[%s]%s", i, i == Args.length ? "" : ","); else code ~= format("args[%s]%s", i, i == Args.length ? "" : ","); } code ~= ");"; return code; } mixin(genCode()); } void targetFunction(ubyte i, ubyte j, uint k, int l) { writefln("i : %s, j : %s, k : %s, l : %s",i,j,k,l); } void main() { myConverterFunc(true,false,10,20); } Thanks. Yes that is one approach. I figured out another approach that seems decent: auto targetFunctionProxy(Args...)(Args args) { import std.meta; return targetFunction!(ReplaceAll!(bool, ubyte, Args))(args); }
Re: Replace (ie: substitute) a type in varadic args
On Tuesday, 2 August 2016 at 08:20:22 UTC, Saurabh Das wrote: On Tuesday, 2 August 2016 at 08:16:48 UTC, Sean Campbell wrote: [...] Thanks. Yes that is one approach. I figured out another approach that seems decent: auto targetFunctionProxy(Args...)(Args args) { import std.meta; return targetFunction!(ReplaceAll!(bool, ubyte, Args))(args); } PS: I'm unsure if this results in additional copying of arguments in the case where there are no bools in the arguments.
Re: Replace (ie: substitute) a type in varadic args
On Tuesday, 2 August 2016 at 07:24:28 UTC, Saurabh Das wrote: How can I substitute the type of an argument received via a varadic template? For example say I want to generalise this scenario: auto myConverterFunction1(bool arg1, bool arg2, ubyte arg3, int arg4) { return targetFunction(cast(ubyte)arg1, cast(ubyte)arg2, arg3, arg4); } So I'll have something like: auto myConverterFunction2(Args...)(Args args) { // Don't know how to do this part... } Basically I need to substitute bool for ubyte to interface with the Java JNI. Thanks, Saurabh Just of the top of my head, using ugly string mixins, this: auto myConverterFunc(Args...)(Args args) { string genCode() { string code = "targetFunction("; foreach (i, Arg; Args) { static if (is(Arg == bool)) code ~= format("cast(ubyte)args[%s]%s", i, i == Args.length ? "" : ","); else code ~= format("args[%s]%s", i, i == Args.length ? "" : ","); } code ~= ");"; return code; } mixin(genCode()); } void targetFunction(ubyte i, ubyte j, uint k, int l) { writefln("i : %s, j : %s, k : %s, l : %s",i,j,k,l); } void main() { myConverterFunc(true,false,10,20); }
Replace (ie: substitute) a type in varadic args
How can I substitute the type of an argument received via a varadic template? For example say I want to generalise this scenario: auto myConverterFunction1(bool arg1, bool arg2, ubyte arg3, int arg4) { return targetFunction(cast(ubyte)arg1, cast(ubyte)arg2, arg3, arg4); } So I'll have something like: auto myConverterFunction2(Args...)(Args args) { // Don't know how to do this part... } Basically I need to substitute bool for ubyte to interface with the Java JNI. Thanks, Saurabh