Develop and Download Open Source Software

Browse Subversion Repository

Contents of /old/lua.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (show annotations) (download)
Tue Mar 25 08:57:51 2008 UTC (16 years ago) by tabasa
File MIME type: text/plain
File size: 1227 byte(s)
+lua test
1 #include <windows.h>
2 BOOL exist(char *file);
3
4 // C++の場合extern "C"が必要
5 extern "C" {
6 #include "lua.h"
7 #include "lualib.h"
8 #include "lauxlib.h"
9 }
10
11 void tes(char *val,char *str){
12 char path[1000];
13 wsprintf(path,"%s/lua.lua",str);
14 if(!exist(path)) return;
15 *str=0;
16 lua_State *L = lua_open();
17 luaL_openlibs(L); // これで以下の個別のライブラリを一度に使えるようにする
18 //luaopen_base(L); // Luaでprint関数が使えるようにする
19 //luaopen_io(L); //
20 //luaopen_string(L); // Luaでstring関係の関数が使えるようにする
21 luaL_dofile(L, path); // Lua scipt 読み込む
22
23
24 // add.lua 内のstr関数をスタックに積む(関数名の文字列"str"を引数に)
25 lua_pushstring(L, "str");
26 lua_gettable(L, LUA_GLOBALSINDEX);
27 //lua_pushnumber(L, 30); // 引数1 文字列"string test"をスタックに
28 lua_pushstring(L, val); // 引数1 文字列"string test"をスタックに
29 lua_pushstring(L, "test"); // 引数2 文字列"string test"をスタックに
30 // 関数を呼ぶ。第2引数は渡す引数の数、第3引数は戻り値の数。
31
32 lua_call(L, 2, 1);
33
34 // スタックの1番目の要素=戻り値を p に入れる(copyしたほうがいい?)
35 char *p=(char*)lua_tostring(L, -1) ;
36 char buffer[900];
37 //sprintf(str,"%f\n",p);
38 sprintf(str,"%s\n",p);
39 //strcat(str,buffer);
40 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision
svn:mime-type text/plain

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26