小编ent*_*ast的帖子

如何正确创建一个nim/nimrod windows dll

我想用nim代码创建一个dll.但我没有注册其他一些出口而不是"NimMainInner".即使我尝试这个简单的例子它不工作:

proc Hellow(): cint {.exportc.} =
  echo("hello")
  return 1
Run Code Online (Sandbox Code Playgroud)

我用nim c --app:lib libh4x.nim 和编译它nim c -d:release --app:lib --no_main libh4x.nim

我用 Nim Compiler Version 0.11.2 (2015-05-04) [Windows: i386]

检查我使用的DLL dllexp.exe.我也尝试用python ctypes加载dll,但我的导出都没有显示或可调用.不过,我可以使用hexeditor在结果dll中看到proc名称.

我错过了什么?

windows dll nim-lang

5
推荐指数
1
解决办法
644
查看次数

如何使用 nim 脚本从标准输入读取?

我将如何通过 nimscript 从标准输入读取?

我试过了:

if readLine(stdin) == "yes":
  exec buildCommand  
Run Code Online (Sandbox Code Playgroud)

我已经运行了脚本

nim c build.nims
Run Code Online (Sandbox Code Playgroud)

我收到

build.nims(50, 13) 错误:未声明的标识符:'stdin'

nim-lang

5
推荐指数
1
解决办法
1669
查看次数

元组中的Nim存储过程引用

Nim Compiler Version 0.13.0 (2016-01-19) [Windows: i386]

如何在元组中存储对过程的引用:

Job = tuple[every:int, timescale:string, timestr:string, jobfunc:proc]

proc run(job: Job, jobfunc: proc): Job =
  result = job
  result.jobfunc = addr jobfunc
Run Code Online (Sandbox Code Playgroud)

在run proc jobfunc中:proc被接受了.在元组中,我得到:

错误:'proc'不是具体类型.

那么什么是proc的类型?

[编辑]

我的最终目标是传递一个带有任意参数的函数run.

Atm我已经设法通过使用一个seq[string]但也许一个人知道一种更通用的方式来解决这个问题.

type
    Job = tuple[every:int, timescale:string, timestr:string, jobfunc: proc(args:seq[string]) {.gcsafe, locks: 0.}]


proc run(job: Job, jobfunc: proc,args:seq[string]= @[""] ): Job =
  # ...
  discard


proc myfunc(args:seq[string]) =
  echo "hello from myfunc ", args
  discard

schedule every(10).seconds.run(myfunc,args= @["foo","uggar"])     
Run Code Online (Sandbox Code Playgroud)

nim-lang

3
推荐指数
1
解决办法
340
查看次数

为什么这个Python Borg/Singleton模式有效

我只是偶然发现网络,发现这些有趣的代码被剪掉了:

http://code.activestate.com/recipes/66531/

class Borg:
    __shared_state = {}
    def __init__(self):
        self.__dict__ = self.__shared_state
    # and whatever else you want in your class -- that's all!
Run Code Online (Sandbox Code Playgroud)

我理解单身是什么,但我不明白特定的代码被剪断了.你能解释一下"__shared_state"是如何/甚至根本改变的?

我在ipython中尝试过:

In [1]: class Borg:
   ...:         __shared_state = {}
   ...:     def __init__(self):
   ...:             self.__dict__ = self.__shared_state
   ...:     # and whatever else you want in your class -- that's all!
   ...: 
In [2]: b1 = Borg()
In [3]: b2 = Borg()
In [4]: b1.foo="123"
In [5]: b2.foo
Out[5]: '123'
In [6]: 
Run Code Online (Sandbox Code Playgroud)

但不能完全理解这是怎么发生的.

python singleton

2
推荐指数
1
解决办法
2377
查看次数

nim re,正则表达式模块未填充匹配组

我想使用 nim 库的正则表达式模块:

import re

var s="""<webSettings>
<add key="MyLaborPassword" value="shadowed" />
<add key="MyLaborUserID" value="shadowed" />
<add key="MyLaborUrl" value="shadowed" />
<add key="DebugSoapLoggingEnabled" value="false" />
  </webSettings>
 """


var matches : seq[string] = @[]

echo s.find(re"""MyLaborP(ass)word""",matches)
echo matches
Run Code Online (Sandbox Code Playgroud)

给我

25
@[]
Run Code Online (Sandbox Code Playgroud)

但我除了:

25
@["ass"]
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

regex nim-lang

2
推荐指数
1
解决办法
514
查看次数

标签 统计

nim-lang ×4

dll ×1

python ×1

regex ×1

singleton ×1

windows ×1