GithubHelp home page GithubHelp logo

jangko / nimlua Goto Github PK

View Code? Open in Web Editor NEW
104.0 10.0 12.0 350 KB

glue code generator to bind Nim and Lua together using Nim's powerful macro

License: MIT License

Nim 94.13% Lua 5.87%
lua wrapper-library glue nim

nimlua's People

Contributors

barroff avatar jangko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nimlua's Issues

inheritance problem

type
  BaseFruit = object of RootObj
    id: int
  Pineapple = object of BaseFruit
    name: string
  Avocado = ref object of BaseFruit
    name: string

proc newAvocado(name: string, id: int): Avocado =
  new(result)
  result.name = name
  result.id = id

proc initPineapple(name: string, id: int): Pineapple =
  result.name = name
  result.id = id

proc getId(self: BaseFruit): int =
  self.id
  
proc getId(self: ref BaseFruit): int =
  self.id

  nimLuaOptions(nloDebug, true)
  L.bindObject(Avocado):
    newAvocado -> "new"
    name(get)
    id(get)
    #getId
  nimLuaOptions(nloDebug, false)
  
  L.bindObject(Pineapple):
    initPineapple -> "init"
    name(get)
    id(get)
    #getId

failed when register getId

Lua library name and use of dynlib pragma

The use of the dynlib pragma at this line using the author defined library names (here, here, here, and again here, here, and here) prevents me from being able to compile and use this library as the package manager i use on linux doesn't follow that naming scheme and i don't have a recourse for trying to change the name. I think the best approach is to remove the matrix of static defined library names, or at least allow it to be overridden using a compile-time define. this type of work really should be left up to the consumer of the library to supply the appropriate flags in their .nim.cfg or .nims file.

typo in readme example import statement

i was trying out this package when i ran into an error with the example in the readme, the import statement is written as:
import nimLua
however, the package gets installed as nimLUA, so it should be written as:
import nimLUA
I am on a case-insensitive file system, so while i don't think that should matter, it does to the nim compiler so i figured it was a mistake or wasn't updated sometime when the package name changed or something so wanted to let you know.

Macro not working with closures

Maybe this is a problem of the macro transpiler/compiler from nim to c.

import nimLUA, os

proc main() =

  let test = 1

  proc abc(a, b: int): int =
    result =  test + a + b

  var L = newNimLua()
  L.bindFunction(abc)

  if L.doString(" print( abc(3,2) ) ") != 0.cint:
    echo L.toString(-1)
    L.pop(1)
  else:
    echo "Working properly"

  L.close()

main()

Error: execution of an external compiler program 'gcc -c -w -O3 -fno-strict-aliasing -I/home/perspectiva/nim/Nim/lib -o /home/perspectiva/apps/test/src/nimcache/test_test.o /home/perspectiva/apps/test/src/nimcache/test_test.c' failed with exit code: 256

/home/perspectiva/apps/test/src/nimcache/test_test.c: In function ‘main_154004’:
/home/perspectiva/apps/test/src/nimcache/test_test.c:379:2: error: incompatible type for argument 2 of ‘pushcfunction_101433’
pushcfunction_101433(L, LOC1);
^
In file included from /home/perspectiva/apps/test/src/nimcache/test_test.c:9:0:
/home/perspectiva/apps/test/src/nimcache/test_test.c:261:23: note: expected ‘Tcfunction100650’ but argument is of type ‘TY154031’
static N_INLINE(void, pushcfunction_101433)(void* L, Tcfunction100650 fn) {
^
/home/perspectiva/nim/Nim/lib/nimbase.h:44:50: note: in definition of macro ‘N_INLINE’

define N_INLINE(rettype, name) inline rettype name

                                              ^

feature: top level proxy

currently, the proxies can only be shared in one scope,
make it enable to to be shared among many lower scope

Wrong behavior when importing other libraries

Hi @jangko :

Thx for this excellent library. Found some bugs when importing other nim libs:

Example:

import nimLUA, os, sequtils, logging


type
  Foo = ref object
    name: string

proc newFoo(name: string): Foo =
  new(result)
  result.name = name

proc addv(f: Foo, a, b: int): int =
  result = 2 * (a + b)

proc addv(f: Foo, a, b: string): string =
  result = "hello: my name is , here is my message: "

var L = newNimLua()
L.bindObject(Foo):
  newFoo -> constructor
  addv

L.dostring """ 
local foo = Foo.new("test")
print(foo:addv(1,2))
print(foo:addv("test","test"))
"""
L.close()

If i add logging it won't compile with the latest nim (0.19.4 [MacOSX: amd64]):

/nim-0.19.4/lib/core/macros.nim(510, 11) Error: type mismatch: got <PState>

EDIT:

The problem when importing sequtils, json, random is that the polymorphism stop working and only the
proc addv(f: Foo, a, b: string): string
get called twice.

import nimLUA, os, sequtils, json, random

returns :

hello: my name is , here is my message:
hello: my name is , here is my message:

how to get lua errors and stack trace?

When I introduce an error in my lua code, all I get is attempt to call a string value and the program stops.

Is there a way to get lua errors?

(Or is this connected to not having access to lua_error? This is my first time trying to do this kind of thing, so I'm quite clueless.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.