My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
LibraryExample  
Very simple Lua library example in D
Featured
Updated Feb 4, 2010 by ande...@gmail.com

Introduction

This will only work for those who use DLua directly, as in, this won't help you with building .dll/.so's for the Lua interpreter.

Code

  • example.d
  • module example;
    
    import dlua.all;
    import std.stdio;
    import lualibrary;
    
    void main()
    {
        lua_State* L = luaL_newstate();
        luaL_openlibs(L);
        lua_pushcfunction(L, &luaopen_example);
        lua_pcall(L, 0, 0, 0);
        luaL_dostring(L, `print(example.func())`);
        lua_close(L);
    }
  • lualibrary.d
  • module lualibrary;
    
    import dlua.all;
    
    private luaL_Reg[] example = [
        {"func", &func},
        {null, null}
    ];
    
    private extern (C) int func (lua_State* L)
    {
        lua_pushstring(L, "aargh!!!");
        return 1;
    }
    
    extern (C) int luaopen_example (lua_State* L)
    {
        luaL_register(L, "example", example.ptr);
        return 1;
    }
Comment by DrGori...@gmail.com, Jan 30, 2008

function dlua.lua.lua_pushcfunction (void,int()(void L)) does not match parameter types (void,int(C )(void L))

wtf?


Sign in to add a comment
Powered by Google Project Hosting