Code Monkey home page Code Monkey logo

bindbc-lua's People

Contributors

brianush1 avatar ichordev avatar mdparker avatar mrcsnm avatar poeticandroid avatar ziltoid1991 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

bindbc-lua's Issues

Can't use luaL_requiref with default luaopen_* functions

This code

import bindbc.lua;

void main()
{
	LuaSupport lua = loadLua();
	auto L = luaL_newstate();
	luaL_requiref(L, "_G", luaopen_base, 0);
	lua_pop(L, 1);
	lua_close(L);
}

generates a compile-time error like this:

source/app.d(32,15): Error: function pointer `luaL_requiref(lua_State* L, const(char)* modname, int function(lua_State* L) nothrow openf, int glb)` is not callable using argument types `(lua_State*, string, extern (C) int function(lua_State* L) nothrow @nogc, int)`
source/app.d(32,15):        cannot pass argument `luaopen_base` of type `extern (C) int function(lua_State* L) nothrow @nogc` to parameter `int function(lua_State* L) nothrow openf`
/usr/bin/dmd failed with exit code 1.

I attempted to hack this by fiddling with @nogc at declarations, but it caused even more problems. I believe some better investigation is required

[1.0.0] Rewrite bindings

  • Consolidate the 4 separate sets of bindings into 1, using conditional compilation.
  • Use BindBC-Common ~>0.1.1.
  • Consider renaming some symbols.
  • Bind older Lua versions, or maybe even LuaJIT?

callback function types are missing `extern(C)`

the callback types like lua_CFunction are currently declared without an extern() so they default to extern(D), but the calling convention for those isn't compatible with extern(C) in all cases:

  • according to issue 20204, extern(D) functions are passed their arguments in reverse order compared to extern(C) (this doesn't affect the common lua_CFunction since it has just 1 parameter)
  • windows/x86 has its D calling convention documented here, which is supposedly different enough from the C one that it had to be specifically documented

one of the types this affects is custom allocator functions since they have 4 parameters:

/+ dub.sdl:
dependency "bindbc-lua" version="~>0.4.1"
subConfigurations "bindbc-lua" "static"  platform="posix"
versions "BindLua_Static" "LUA_54"       platform="posix"
libs "lua5.4"                            platform="posix"
+/
import core.stdc.stdlib;
import std.exception;
import std.stdio;
import bindbc.lua;

// https://www.lua.org/manual/5.4/manual.html#lua_Alloc
extern (C) // <-- change to extern(D) and it breaks
void* myalloc(void* ud, void* ptr, size_t osize, size_t nsize) nothrow
{
	writefln("ud=%s ptr=%s osize=%s nsize=%s", ud, ptr, osize, nsize).assumeWontThrow;
	if (nsize == 0)
		{ free(ptr); return null; }
	else
		return realloc(ptr, nsize);
}

// lua_Alloc with D calling convention (same as bindbc-lua)
alias lua_Alloc_D = extern (D) void* function(void* ud, void* ptr, size_t osize, size_t nsize) nothrow;

void main()
{
	lua_State* L = luaL_newstate();
	lua_setallocf(L, cast(lua_Alloc_D)&myalloc, null);
	luaL_openlibs(L);
	if (LUA_OK != luaL_dostring(L, `
	print("hello world")
	`)) lua_error(L);
	lua_close(L);
}

with extern(C) on the allocator function, it works normally but if changed to extern(D), it prints bogus values and crashes (tested on linux with dmd, 64-bit and 32-bit)

in general, any function that's going to be called by C code should have extern(C) to work correctly

Error in v54 code

I get this error whenever I'm trying to using lua 5.4 with bindbc-lua:

../../../.dub/packages/bindbc-lua-0.4.0/bindbc-lua/source/bindbc/lua/v54/package.d(323,9): Error: return expression expected

Although I think it's something on my end, as it seems there is a return in the source code, but I'm not sure?

Lua 5.3 bindings are to Lua 5.2

LuaSupport loadLua()
{
version(Windows) {
const(char)[][3] libNames = ["lua5.2.dll", "lua52.dll", "lua5.2.4.dll"];
}
else version(OSX) {
const(char)[][1] libNames = "liblua.5.2.dylib";
}
else version(Posix) {
const(char)[][1] libNames = "liblua.so.5.2";
}
else static assert(0, "bindbc-lua support for Lua 5.2 is not implemented on this platform.");
LuaSupport ret;
foreach(name; libNames) {
ret = loadLua(name.ptr);
if(ret != LuaSupport.noLibrary) break;
}
return ret;
}

Looks like the 5.3 bindings just arent done yet, but it was a pain to figure out why it wasnt finding my shared library, so this issue can just serve as a warning

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.