main.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. *
  4. * Main app
  5. *
  6. * Created by Manoël Trapier
  7. * Copyright (c) 2020 986-Studio.
  8. *
  9. */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <math.h>
  13. extern "C" {
  14. #include <lua.h>
  15. #include <lauxlib.h>
  16. #include <lualib.h>
  17. }
  18. static int l_sin (lua_State *L) {
  19. double d = luaL_checknumber(L, 1); /* get argument */
  20. lua_pushnumber(L, sin(d)); /* push result */
  21. return 1; /* number of results */
  22. }
  23. #if 0
  24. int main(int argc, char *argv[])
  25. {
  26. char buff[256];
  27. int error;
  28. lua_State *L = luaL_newstate(); /* opens Lua */
  29. luaL_openlibs(L); /* opens the basic library */
  30. lua_pushcfunction(L, l_sin);
  31. lua_setglobal(L, "mysin");
  32. printf("[0]>");
  33. while (fgets(buff, sizeof(buff), stdin) != NULL)
  34. {
  35. error = luaL_loadstring(L, buff) || lua_pcall(L, 0, LUA_MULTRET, 0);
  36. if (error)
  37. {
  38. fprintf(stderr, "%s\n", lua_tostring(L, -1));
  39. lua_pop(L, 1); /* pop error message from the stack */
  40. }
  41. printf("[%d]>", lua_gettop(L));
  42. }
  43. lua_close(L);
  44. return 0;
  45. }
  46. #endif