better c fibers

2021-09-21 Thread Abby via Digitalmars-d-learn

Hi there,
I'm new in dlang I specially like betterC. I was hoping that d 
fibers would be implemented in without using classes, but there 
are not. Is there another way how to use async/await in dlang 
better c?


Thank you for your help
Abby


mixins

2021-11-17 Thread Abby via Digitalmars-d-learn
Hello I would like to create validation mixin or mixin template 
which would return on error.


Something like this:


```
mixin template Validate(a, b)
{
if(a > b)
{
   writeln("invalid input");
   return false;
}
}

bool test(a,b)
{
mixin Validate!(a,b);


on valid code


return true;
}
```



package libs on windows

2022-02-01 Thread Abby via Digitalmars-d-learn

Hi there,
I'm using d2sqlite3 package on windows with dub, the problem I 
have is that when I compiling the app linking fails because LINK 
: fatal error LNK1181: cannot open input file 'sqlite3.lib'. I 
would like to know if there is a way to set path to lib to 
downloaded with package instead of harcoded.


libs 
"C:\\Users\\abby\\AppData\\Local\\dub\\packages\\d2sqlite3-0.18.3\\d2sqlite3\\source\\d2sqlite3\\lib\\win64\\sqlite3" platform="windows"


Thank you very much for your help


betterC CTFE nested switch

2020-02-17 Thread Abby via Digitalmars-d-learn

Hi there guys,
I was trying to generated code during compile time. Bassicly I'm 
creating a tokenizer and I would like to generated nested switch 
using betterC.


Basically convert something like this:

enum tokens =
[
['!', '='],
['>', '='],
['>'],
];

to:

switch(str[i])
{
case '!':
switch(str[i + 1])
{
case '=':
onToken(['!', '=']);
break;
default: break;
}
break;
case '>':
switch(str[i + 1])
{
case '=':
onToken(['>', '=']);
break;
default:
onToken(['>']);
break;
}
break;
default: break;
}

but right now I'm stuck and I don't know how to achieve this. I 
was able to find out that:


1) Switches has to be labeled and the only way I know how to do 
so is to use string code and then mixing it. I was hoping for 
example to mixing only labels before switch and after continue 
and break but this does not seem to work :/


2) Format does not work in compile time using betterC (sprintf 
also does not work



Thank you very much for any kind if help
Kind regards Abby



Re: betterC CTFE nested switch

2020-02-17 Thread Abby via Digitalmars-d-learn

On Monday, 17 February 2020 at 11:05:46 UTC, Stefan Koch wrote:

On Monday, 17 February 2020 at 10:18:32 UTC, Abby wrote:

Hi there guys,
I was trying to generated code during compile time. Bassicly 
I'm creating a tokenizer and I would like to generated nested 
switch using betterC.


[...]


I have a ctfe compatible string formatter, you should be to 
find it here

https://forum.dlang.org/post/hmyxvknbdqtlnxvqq...@forum.dlang.org

I hope that helps,

Regards, Stefan
:


Hi Stefan, thank you very much for your reply but I could not 
find the source code or package name anywhere in that forum 
thread, I was only able to find this 
https://github.com/UplinkCoder/ctfeutils on github, but it's 
empty for me. Can you please help and point me to somewhere so I 
can try it out?


Thank you very much

Kind regards Abby


Re: betterC CTFE nested switch

2020-02-18 Thread Abby via Digitalmars-d-learn

On Monday, 17 February 2020 at 19:02:50 UTC, Stefan Koch wrote:


Sorry I just realized I never published the code.
I am going to add it to ctfeutils.


Thank you very much


Re: betterC CTFE nested switch

2020-02-21 Thread Abby via Digitalmars-d-learn

On Monday, 17 February 2020 at 19:02:50 UTC, Stefan Koch wrote:

Sorry I just realized I never published the code.
I am going to add it to ctfeutils.


Hi Stefan,
I'm sorry to bother you, I just wanted to kindly ask if you would 
upload the formatter to ctfeutils on github it would help me alot.


Thank you very much
Kind regards Abby


String switch is odd using betterC

2020-02-26 Thread Abby via Digitalmars-d-learn

I have a simple enum of strings like so:

enum Alphabet : string
{
a = "A",
b = "B",
c = "C",
d = "D",
e = "E",
f = "F",
g = "G"
}

and then simple final switch like so:

extern(C) void main()
{
auto s = Alphabet.f;
final switch(s)
{
case Alphabet.a: break;
case Alphabet.b: break;
case Alphabet.c: break;
case Alphabet.d: break;
case Alphabet.e: break;
case Alphabet.f: break;
case Alphabet.g: break;
}
}

The problem I have is that this causes:

/dlang/dmd/linux/bin64/../../src/druntime/import/object.d(2999): 
Error: TypeInfo cannot be used with -betterC


Odd think is that wehen I remove g from my enum it compiles just 
fine, so it seems that this compilation error occurs only when my 
enum has more then 6 members.


Any idea why?


Re: String switch is odd using betterC

2020-02-26 Thread Abby via Digitalmars-d-learn

On Wednesday, 26 February 2020 at 08:25:00 UTC, Abby wrote:

/dlang/dmd/linux/bin64/../../src/druntime/import/object.d(2999): Error: 
TypeInfo cannot be used with -betterC

Odd think is that wehen I remove g from my enum it compiles 
just fine, so it seems that this compilation error occurs only 
when my enum has more then 6 members.


Any idea why?


Ok so this is enough to reproduce the problem

extern(C) void main()
{
auto s = "F";
final switch(s)
{
case "A": break;
case "B": break;
case "C": break;
case "D": break;
case "E": break;
case "F": break;
case "G": break;
}
}


Re: String switch is odd using betterC

2020-02-26 Thread Abby via Digitalmars-d-learn

On Wednesday, 26 February 2020 at 08:25:00 UTC, Abby wrote:

Any idea why?


Ok so this is enough to produce the same result, it seems that 
there is a problem in string switch when there is more the 6 
cases.


extern(C) void main()
{
auto s = "F";
final switch(s)
{
case "A": break;
case "B": break;
case "C": break;
case "D": break;
case "E": break;
case "F": break;
case "G": break;
}
}


string to char* in betterC

2020-03-11 Thread Abby via Digitalmars-d-learn
What is the proper way to get char* from string which is used in 
c functions? toStringz does returns:


/usr/include/dmd/phobos/std/array.d(965,49): Error: TypeInfo 
cannot be used with -betterC


and I think string.ptr is not safe because it's not zero 
termined. So what should I do? realloc each string with /0?


Thank you for your help


exporting function from betterc to windows dll

2020-03-14 Thread Abby via Digitalmars-d-learn
I would like to export some functions from my bettec dll for 
dotnet core application in windows.


Right now I have compiled dll using dmd v2.091.0-dirty simply by 
´dub build´


this is the function I have

extern(C) char* test_echo(const(char)* line, size_t len,  ref 
size_t resLen)

{
enum format = "{\"message\": \"%s\"}\n";

auto response = cast(char*)malloc(format.length + len);
resLen = sprintf(response, format, line);
return response;
}

and this is my dotnet core equivalent

[DllImport(DllName, CallingConvention = 
CallingConvention.StdCall)]
static extern IntPtr 
test_echo([MarshalAs(UnmanagedType.LPStr)]string line, ulong len, 
out ulong resLen);


This works for me in linux but does not in windows, any idea what 
I'm doing wrong?


This is the output from dotnet core

Unhandled exception. System.EntryPointNotFoundException: Unable 
to find an entry point named 'test_echo' in DLL 'test.dll'


dub libs from home directory on windows

2020-03-18 Thread Abby via Digitalmars-d-learn

Hi there,
I'm using d2sqlite3 which has dependency on sqlite3.lib. When I'm 
building my app on windows I have a dub.sdl which has a line


libs 
"%USERPROFILE%/AppData/Local/dub/packages/d2sqlite3-0.18.3/d2sqlite3/lib/win64/sqlite3" platform="windows-x86_64-dmd"


but unless I specify full path using specific user profile name 
on windows like so


"c:/user/abby/AppData/Local/dub/packages/d2sqlite3-0.18.3/d2sqlite3/lib/win64/sqlite3"

I cannot build my app, so I was wondering if there is some clever 
way to solve this without hardcoded path to my profile name.


Thank you very much for your help.


return val if

2020-03-22 Thread Abby via Digitalmars-d-learn

Is there a way to create a template that would do the same is glib

g_return_val_if_fail() 
(https://developer.gnome.org/glib/stable/glib-Warnings-and-Assertions.html#g-return-val-if-fail)


I was hoping something like this would work

template returnValIfFail(alias expr, alias val)
{
if(expr) return val;
}