Git Product home page Git Product logo

luad's People

Contributors

aubade avatar belm0 avatar goughy avatar jakobovrum avatar jessekphillips avatar john-colvin avatar turkeyman 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  avatar  avatar  avatar  avatar

luad's Issues

support for class inheritance

Sooner or later cross-border inheritance is needed.
I'm not sure if exposing D's class hierarchy is necessary or possible (maybe for having an array of instances in lua, i.e. like CommonBaseClass[] in D?)

But I'm sure I'd like to be able to define custom classes in Lua as well as export certain D classes (e.g. MovingEntity) which can then be inherited in Lua. The other way around doesn't make much sense to me.

The question is in which ways this could be achieved.

Returning multiple unpacked values to Lua from a D function

I imagine this might be another ambiguity-dilemma issue, but in my code I've got a D-side function that does some processing and then returns results filtered through a LuaFunction.

However, if I pass the return value from LuaFunction directly back to Lua, the values are packed in an array.

For the moment, I can add a wrapper function Lua-side to run unpack() first, but it seems a little bit wasteful to just unpack what D already spent memory packing; it'd be nice to have a way of doing this directly.

stack.d compile fails

luad/stack.d(450): Error: cannot implicitly convert expression (value.length) of type ulong to int

segfault due to throwing in panic handler

import luad.all;

void main()
{
    auto lua = new LuaState;
    lua.doString("func()");
}

Stack unwinding doesn't work reliably from the panic handler as
it requires C-like stacks and -fno-omit-frame-pointer for the interpreter.

Creating a LuaObject from D

So, I think I "could" create a LuaObject manually via pushValue, and popValue in luad.stack; however, this solution doesn't seem very elegant. I'm wondering if you know of a better way to write a function like this:
LuaObject convert() {
return 42;
}

(note: changing the return type of convert() is not applicable).

Phonebook example regression

The phonebook example no longer works when compiling with RDMD on 64-bit Linux, it returns these errors:

LuaD/luad/conversions/structs.d(51): Error: no property '__fieldDtor' for type 'Contact'
LuaD/luad/conversions/structs.d(51): Error: (Contact).__fieldDtor cannot be resolved
LuaD/luad/conversions/structs.d(54): Error: no property '__fieldDtor' for type 'Contact'
LuaD/luad/conversions/structs.d(54): Error: no property '__fieldDtor' for type 'Contact'

Additionally, it still wouldn't work correctly since contacts.lua has been moved, yet line 31of phonebook.d was not changed to reflect the change.

automatic documentation generation

Beware: this is just a premature thought.
Every app that exposes some of its functions and classes to Lua probably wants to generate some API documentation to pass it over to the scripting team.
Especially when the API is changed quite often during the development of the main app it is desirable to automate this procedure.

I'm not sure if LuaD can do anything to ease that. Of course you could output some text in the registerClass etc. functions that at least describe what functions are available but you probably can't get ahold of their ddoc comments.

Can't assign Lua function to Lua variable

When using Lua.get to obtain a function and assign it to a Lua variable the compiler refuses due to the protection level of push in LuaObject (protected).

import luad.all;
import std.stdio;

void main() {
   auto lua = new LuaState;

   lua["print"] = lua.get!LuaFunction("print");
}

support variable number of return values in function conversion

Regarding converting D functions for use in Lua, while return of multiple values is supported, it doesn't appear possible to return a variable number of values. Variable return value count is used often in Lua API's. I understand it can be done from the C API, but I'd argue that the function converter should support this for convenience and consistency.

On the related topic of multiple return types, I'm questioning the use of static arrays (in addition to tuples). It's adding magic for a limited use case-- how often do you return multiple values of the same type? And what's wrong with using tuple in that case-- e.g. "tuple(5, 10)"?

I have a proposal to address both of these:

  • define an attribute which signals that a function's return value of type T[] should be unpacked into multiple values
  • improve std.variant conversion so that we can use Variant[] as return type
  • remove static-array-return special case from the function converter (tuples are still useful for extra compile-time bug coverage and performance when there are a fixed number of values)

So as long as a D function is tagged with the attribute, you could return a variable number of arguments via a dynamic array. If the values need to have different types, use Variant[]. The attribute still works with static arrays too, of course.

Pushed class instances are not rooted in the D GC (formerly "D's Garbage Collector is too aggressive")

An object in D needs to have a root in the garbage collector to not be collected. This demonstrates the problem:

class test {
  public {
    int member = 42;
  }
}
LuaObject generate() {
  return new test();
}

auto lua = new LuaState();
lua["generate"] = &generate;
lua.doString("a = generate()");
// 10 seconds later... (or enough time for D to collect garbage)
lua.doString("print(a.member)")

The call to print(a.member) causes an object.Error: Access Violation error. (Also, with my modified version of LuaD to fix this issue an exception is thrown when finalizing an instance of class luad.lfunction.LuaFunction)

The fix is shown below:
import core.gc;
class LuaMemoryPreserver {
this() { gc.addRoot(cast(void)this); }
final void finalize() { gc.removeRoot(cast(void)this); }
private static GC _gc;
}

class test: LuaMemoryPreserver { ... }

//... same code after the definition of test as above

This fixes the issue because I modified luad.conversions.classes.pushMeta and added this at line 47
static if(__traits(compiles, obj.finalize)) {
pushValue(L, &obj.finalize);
lua_setfield(L, -2, "__gc");
}

This works by using userdata metatables to call a custom "dealloc" function in D when Lua is done with the object, but I'm not sure if I'm even using the library correctly, as in, this should be a non-issue.

Also, as an aside question, how does one push nil, as in
LuaObject func() { return nil; } // pushes nil to lua, doesn't compile

Thanks.

inconsistent use of bool in C API

I noticed the C API uses bool in place of int for some functions but not others (e.g. lua_equal vs. lua_isnumber).

I'm also wondering how bool can be safely used in these definitions since D defines bool size as 1 byte, while int is 4. Is that making some assumptions about endianess?

Add documentation

Complete with gh-pages and all that. I wonder how good Doxygen is for D?

Lua global print value is nil

When attempting to print from Lua the result is an error:

luad.error.LuaError: [string "print("Hello")"]:1: attempt to call global 'print'
(a nil value)

import luad.all;

import std.stdio;


void main() {
   auto lua = new LuaState;

   lua.doString("print(\"Hello\")");
}

makefile compile problem

When I try to compile the library using the cmd make in the base directory I get this:
Error on line 1: expecting target : dependencies error.
I am not experienced in makefiles so am I doing something wrong? Help with a little bit of explanation would be nice.

Also do I need to download the lua51.lib file? I want to make static library not dll. Thanks

lua stack trace

Currently it only shows the error message (at least with LuaState.(doString|doFile))
A stack trace would be helpful.

A way to pass structs by reference?

Given that class object support is still rudimentary, I'm looking for ways of easily sharing data between my program and Lua scripts. At the moment I'm looking at storing data in structs, but I'm bumping up against some limitations:

First, it seems that there's no way to pass a struct by reference to a Lua function. I've also tried putting getter and setter methods on the struct, in case that made a difference, and it didn't seem to.

Second, LuaD doesn't seem to be able to register a pointer-to-struct as a data type, and you can't pass one to a Lua function without that.

Return value of last statement/chunk?

Is there a way to access the value returned from the last statement to be executed? LuaState.doString returns void, but I'd like to get the value returned by the operation for a REPL-like environment.

If there is no facility for this now, is this an easy feature to add?

Linker Error: Symbol Undefined with opAssign

Edit: Sorry if this is an incorrect vector for asking for help with issues like this. I'm new to github, and I was unable to find any contact information to speak to the developer(s) directly. I was at a loss where else to ask about this.

Hello. I've been trying to get LuaD up and running in my personal engine. Things have been going fairly well (I had to update my D compiler, at one point), but I'm running into a linker error that I can't figure out.

I'm getting the following error message:
"Error 42: Symbol Undefined _D4luad4base9LuaObject8opAssignMFNbNcNeS4luad4base9LuaObjectZS4luad4base9LuaObject (nothrow ref @trusted luad.base.LuaObject luad.base.LuaObject.opAssign(luad.base.LuaObject))"

I believe the issue has something to do with the fact that I'm compiling my engine into a library, and then linking that library in another project. The library project compiles just fine, but it's the second project which includes it that displays this error. I've linked luad-lib (or luad-d.lib) and lua51.lib in both projects.

I'm not entirely sure where the issue lies. Is it an issue with LuaD? Is it an issue with the D compiler? Or is it an issue with my inability to set things up correctly? I've been picking away at the problem through Google for a few days now, but after getting no where, I decided it would be best to start asking questions at the source.

Add D1 support

Shouldn't be too bad since no D2 features are that rooted, I'd love some help for this though

Return a LuaObject from a D function

At the moment, when making a D function for use in Lua, there doesn't seem to be a way of accessing the caller's LuaState, and there doesn't seem to be a way to construct a LuaObject to return to Lua without one. Is there any way of doing this at all elegantly? (I know I can just return a D type, but in this case I actually need Lua's polymorphism on the D end of things)

examples make fails

Commit a471f2e neglected to adjust Makefile.

make: *** No rule to make target `dump/dump.d', needed by `dump/dump'.  Stop.

Calling a delegate containing a LuaFunction throws an exception

Storing a LuaFunction inside of a delegate and then calling that delegate causes an exception.

void registeredLuaFunction(LuaFunction luaFunc) {
    auto func = (Entity e) {luaFunc(new EntityWrapper(e));};
    func(new Entity());
}

(EntityWrapper "wraps" Entity so that it is usable in Lua)

This issues "An exception was thrown while finalizing an instance of class luad.state.LuaState".

Any ideas? Sadly, if this is not resolved then I will probably not be able to use LuaD.

Missing imports in assocarrays and state

I was doing some testing for considering use in my project (Windows DMD 2.050) and came across some missing import statements. The code below is what I was using. If I can't find a way to attach a patch I'll email it.

import luad.all;
import std.stdio;

void main() {
   auto lua = new LuaState;
   lua["SomeNumber"] = 12.3;

   lua["sayit"] = () {
      writeln(lua["SomeNumber"]);
   };

   lua["mathit"] = () {
      lua.doString("SomeNumber = SomeNumber + 5");
   };

   lua.doString("sayit()");
   lua.doString("mathit()");
   lua.doString("sayit()");
}

lost merge for pushvfstring

Pull #47 was supposedly merged into master, but it's nowhere to be found. Perhaps I'm misunderstanding git, or there was an improper rebase.

#47

Allow for shared library building

Since the compilers are now able to build shared libraries, please update your make process to allow building LuaD as a shared library.

LUAD_DFLAGS += -shared -X -Xf"lib/libluad.json" -deps="lib/libluad.deps"

(Notice: replace "-lib" by "-shared")

Bug in DMD 2.064 breaks LuaD

This isn't your fault, but I think this should be posted here just in case anyone finds a workaround before the bug is fixed:

import luad.all;

struct Position {
    double x,y;
}

void main() {
    auto state = new LuaState;
    state.doString("pos = {x = 1, y = 2}");
    auto pos = state.get!Position("pos");
}

will not compile (assertion failure in dmd's backend).

import luad.all;

struct Position {
    double x,y;
}

void main() {
    auto state = new LuaState;
    state.doString("pos = {x = 1, y = 2}");
    auto pos = state.globals.get!Position("pos");
}

works.

import luad.all;
import std.stdio;

struct Position {
    double x,y;
}

Position getPos(LuaState state) {
    return state.globals.get!Position("pos");
}

void main() {
    LuaState state = new LuaState;
    state.doString("pos = {x = 1, y = 2}");
    writeln(getPos(state));
}

doesn't work. No, I don't get it either.

lua_tointeger conversions fail

I'm trying to compile the Phonebook example, and apparently it doesn't work because of this:

LuaD/luad/stack.d(186): Error: cannot implicitly convert expression (lua_tointeger(L,idx)) of type long to uint

You can see the full compilation command and output here: http://pastebin.com/9mc1y6zd

Using DMD64 2.054, RDMD build 20110706 on Linux.

full variant support

Without this it isn't possible for a Lua function to return variable number of arguments of differing type (see issue #42).

(This may not be high priority but I want to document it.)

luad_unittest segfault

I'm seeing luad_unittest segfault on Ubuntu x86_64 with DMD64 v2.059.

The backtrace is lacking symbol info so I'm not sure how to proceed. E.g.:

#0  0x00000000004a9280 in rt.deh2.terminate() ()
No symbol table info available.
#1  0x000000000049a576 in _d_throwc ()
No symbol table info available.
#2  0x0000000000000001 in ?? ()
No symbol table info available.
#3  0x000000000000002a in ?? ()
No symbol table info available.
...

Function wrapping wrongly requires at least one argument passed to a variadic function

D rules permit passing zero arguments to a variadic function, but LuaD's current wrapping doesn't seem to permit this.

This code illustrates the issue:

import luad.all;
void func(LuaObject[] args...) {
    import std.stdio;
    writeln("Arguments passed: ", args.length);
}


void main() {
    auto lua = new LuaState();
    lua.openLibs();
    lua.globals["func"] = &func;
    func(); //Works fine


         lua.doString(`
        func()
    `); //Throws an exception.
}

I've fixed this locally by manually subtracting one from the required-argument-count check if std.traits.variadicFunctionStyle != Variadic.no. If this is an acceptible solution I'd be happy to file a pull request.

Finish tutorial

There is a tutorial on the wiki, but it's not finished. I will work on this from time to time, but as always, contributions are welcome!

If you're new to Lua, D and/or LuaD, please check out the tutorial and post some feedback here about it, and what you'd like to see included in the future. Thanks!

Expand on class conversion support

Stuff that needs to be supported, if you happen to see this issue, please help me expand on this list.

  • Support all translatable operator overloads
  • Support entire overload sets, not just the first defined overload
  • Fix virtual function behaviour [done]
  • Support const and immutable class references
  • Properties and public data fields
  • Class registration with constructors and static members

Unintentional emphasis in Ddoc

This is a very small and simple to fix bug, but it's still worth noting: when reading through the documentation written in Ddoc, you can see a whole lot of unintended emphasis in the documentation, and it makes it rather difficult to read. For example, on this page:

http://jakobovrum.github.com/LuaD/luad/state.html

The words "code", "path", "registry", "wrap", "get", "set", "opIndex" and "opIndexAssign" are emphasised in the description of those functions, but apparently they should not be, and with CanDyDoc it makes it hard to read. According to Ddoc documentation, you can get rid of that unintentional emphasis by putting a "_" character before the words to make Ddoc stop emphasising those particular words.

Compilation fails due to template mismatch

I just recently upgraded to the latest DMD (2.058) as well as to the latest LuaD, and it seems that there is an issue while trying to compile it on 64-bit Linux (tested in on Windows and it compiled just fine, so it's probably somewhat platform-specific). The errors that DMD gives me are:

../include/LuaD/luad/stack.d(321): Error: template luad.stack.getValue(T,alias typeMismatchHandler = defaultTypeMismatch) does not match any function template declaration
../include/LuaD/luad/stack.d(321): Error: template luad.stack.getValue(T,alias typeMismatchHandler = defaultTypeMismatch) cannot deduce template function from argument types !(LuaObject)(void**,ulong)
../include/LuaD/luad/stack.d(321): Error: template instance getValue!(LuaObject) errors instantiating template
../include/LuaD/luad/stack.d(324): Error: function luad.c.lua.lua_pop (void** L, int n) is not callable using argument types (void**,ulong)
../include/LuaD/luad/stack.d(324): Error: cannot implicitly convert expression (n) of type ulong to int
../include/LuaD/luad/state.d(248): Error: template instance luad.stack.popStack!(LuaObject) error instantiating

And my compilation script includes LuaD files in this order:

../include/LuaD/luad/*.d ../include/LuaD/luad/conversions/*.d ../include/LuaD/luad/c/*.d

Post example requests here

If there's any LuaD usage you're not sure about, ask here and I'll try to answer, and possibly clarify the documentation on it.

fix lua_State declaration

currently:

alias void* lua_State; // TODO: Should be more type-safe

Since Lua API functions accept lua_State*, the result is that D considers them to have void** L in their signature. The following seems to work as a C forward declaration and yields more sensible function types:

struct lua_State;

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.