jangko / nimlua Goto Github PK
View Code? Open in Web Editor NEWglue code generator to bind Nim and Lua together using Nim's powerful macro
License: MIT License
glue code generator to bind Nim and Lua together using Nim's powerful macro
License: MIT License
plain object/tuple crash because no gc_ref
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
What do you think about the more beautiful text output? For myself, I use this:
https://gist.github.com/Jipok/68ad1cc5364e5bd27496248226bc20e8
The code is far from perfect, but it works.
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.
dont use lua_checkxxx
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.
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’
^
This could be used for callbacks, etc.
currently, the proxies can only be shared in one scope,
make it enable to to be shared among many lower scope
need a safe lua_error
use compile time key to store userdata metatable on REGISTRYINDEX
see this
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:
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.)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.