OK, so I got a c2nim version working. Strangely, instead of a random integer or
the correct value img.w/h is now returning 0. Only obvious difference between
its implementation and mine is that it used the bycopy pragma on the Image
type, but there must be something else going on. Not sure what
It appears most of the comments made to my original post are not addressing the
issue I raised, which is increasing the exposure of Nim. In fact, some
commentators seem to be suggesting they don't see a high need to increase Nim's
exposure. I think this is a very insular view and attitude of
I think so. I tried it with both typed and untyped macro arguments. What's
funny, it works as expected for untyped ones:
macro sth(code: untyped): untyped =
echo code.repr
sth:
let s = 5
echo s
But not for typed:
macro sth(code:
Thanks for the hint, the macro becomes simpler and better:
macro expandToFile(filepath: string, body: typed): untyped =
result = body # optional
writeFile($filepath, repr(body))
Maybe a similar mod could be applied to the
As for writing REALLY Python-like Nim code, please have a look at
[nimpylib](https://github.com/Yardanico/nimpylib). In some simple cases and
when good design-patterns are followed in the Python code, it can get almost
1:1.
ast = getAst(inner(body))
code = $toStrLit(ast)
is replaceable by:
code = body.repr
Other than that, it seems to be a bug as body.repr.parseStmt should be an
identity and here it's not (parse error due to invalid indentation).
Thanks. Adding importc didn't work (still random integers), I'll look into
c2nim.
adrianv, that makes better sense now. Udiknedormin, I agree here. I think that
a block should lead to deconstruction.
Works like a charm. Exactly what I was looking for. Thanks, man!
You likely need to `importc` the fields...
type
target* = object
ptrTarget* = ptr target
image* = object #prototype for this is available at
https://grimfang4.github.io/sdl-gpu/structGPU__Image.html if that's helpful
data* {.importc.}: pointer
w*
Here is how I would do it:
import streams, murmur, strutils
const size = 1_048_576
var
i = open("input")
buf = newString(size)
fhash: BiggestInt = 0
while i.readChars(buf, 0, size) > 0:
fhash += hash(buf)
echo fhash
@2vg Nice! I'm going to give it a try. I do need to support Windows; that is
my primary target for the client (the server will be primarily Linux).
I won't need encryption until I release the first alpha version, and I'm a long
way away. If you plan to have a look at SSL support, that would be
I'm trying to expand a template and write the resulting code into a nim file.
I've tried this approach, inspired by `expandMacros`:
import macros
template test(msg: string, body: untyped): typed =
body
proc testproc(s: string) =
echo s & ": " & $rows
Consider this example:
iterator fibo(a, b: int): int {.closure.} =
var
a = a
b = b
while true:
yield a
(a, b) = (b, a+b)
let x = fibo
for _ in 1 .. 5:
echo x(1, 1)
echo x(10, 20)
echo x(100, 999)
Howdy ho nimorinos,
I've been wrapping [sdl-gpu](https://github.com/grimfang4/sdl-gpu) , and it's
been going pretty well considering I'm a novice programmer with no experience
in C and just bit in nim, but I've run into a snag. To access the dimensions of
images in sdl-gpu, you call image->w
I have seen evt-tls now.
dont the code base to look so big, so I would like to write a wrapper or
implement it pure.
I am very new to nim and pulling my hear out trying to read a large file into a
buffer in chunks and hash the buffer's content like so:
import streams, murmur, strutils
const size = 1_048_576
var
i = open("input")
buf: array[size, char]
fhash:
Yes, correct. I was about to write tooling to transpile a bunch of python code
about 60k LOC to C++ for various reasons, one of them is that I cannot deploy
Python on iOS. Anwway, I was looking for a sollution to save time, or I do not
want to reinvent the wheel. This is how I arrived here. For
Well, it is not an issue but I don't get why it doesn't work for a block:
{.experimental.}
type MyObj = object
a: int
proc `=destroy`(m: MyObj) =
echo "Destruct"
block:
let x = MyObj(a: 5)
I find it misleading as a block should
Rewriting doesn't have to be bad. One of the reasons is that it may be possible
to write a more efficient implementation more easily in another language (see:
Rust's enums are faster than C++ virtual, especially for small ones). Also:
just like a wrapper with native types (uses seq instead of
20 matches
Mail list logo