lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Luiz Henrique de Figueiredo once stated:
> Try the code below and then compare to your own.

  32 bit Linux, Lua 5.1.4 (with all the patches [1]) and the following C
code:


#include <stdio.h>
#include <lua.h>

static int construct(lua_State *L)
{
  int stack_size;
  
  stack_size = lua_gettop(L);
  printf("construct %d items in stack\n",stack_size);
  lua_pushinteger(L,stack_size);
  return 1;
}

int luaopen_construct(lua_State *L)
{
  lua_register(L,"construct",construct);
  return 0;
}

[spc]lucy:~/source/lua/C>gcc -shared -fPIC -o construct.so construct.c 
[spc]lucy:~/source/lua/C>lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require "construct"
> print(construct(10,20,30,40))
construct 4 items in stack
4
> 

  -spc (In other words, it worked for me)